Contract 0x68d8d0C1738905814C786351918986ec50BcD7b9

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

Contract Overview

Balance:
Txn Hash Method
Block
From
To
Value
0xce92d0fefd8bddab6c4dcb8e141fb1698a7d9d87c37efd2811d71350c42f9f3a0x6080604088926732023-05-04 15:16:54351 days 13 hrs ago0x9841484a4a6c0b61c4eea71376d76453fd05ec9c IN  Create: PositionalMarketManager0 ETH0.0980655524570.00001
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0xe307189c9bc10ecc3130e695f085e030b3f9e252fef8b25f663a62c7bd76cd2689301632023-05-05 12:06:34350 days 16 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0xe307189c9bc10ecc3130e695f085e030b3f9e252fef8b25f663a62c7bd76cd2689301632023-05-05 12:06:34350 days 16 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0xe307189c9bc10ecc3130e695f085e030b3f9e252fef8b25f663a62c7bd76cd2689301632023-05-05 12:06:34350 days 16 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0xe307189c9bc10ecc3130e695f085e030b3f9e252fef8b25f663a62c7bd76cd2689301632023-05-05 12:06:34350 days 16 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x582cb46a0ba8876177371d03c55e61f14b67000e67bcfd2901a89f294565733089284612023-05-05 11:09:50350 days 17 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x582cb46a0ba8876177371d03c55e61f14b67000e67bcfd2901a89f294565733089284612023-05-05 11:09:50350 days 17 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x67d11e41242bed542bf4caad7a3323a8aa0a4ee77112844ced788623beaaf21889284482023-05-05 11:09:24350 days 17 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x67d11e41242bed542bf4caad7a3323a8aa0a4ee77112844ced788623beaaf21889284482023-05-05 11:09:24350 days 17 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x60e1993a43ac1bc7fbc74acfefe421eef3e1d1dda6be60ed0aee84bcf5f8f9cd89284262023-05-05 11:08:40350 days 17 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x60e1993a43ac1bc7fbc74acfefe421eef3e1d1dda6be60ed0aee84bcf5f8f9cd89284262023-05-05 11:08:40350 days 17 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0xf5ea413b1b00c616af4c35e9745f210ceb78584106cd9ff55a4baa852b879c6e89283862023-05-05 11:07:20350 days 17 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0xf5ea413b1b00c616af4c35e9745f210ceb78584106cd9ff55a4baa852b879c6e89283862023-05-05 11:07:20350 days 17 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0xaab0bc5730cdb9b5e2ff0eb7371fd202264279bf8a79266eae47d640b9eb701089283582023-05-05 11:06:24350 days 17 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0xaab0bc5730cdb9b5e2ff0eb7371fd202264279bf8a79266eae47d640b9eb701089283582023-05-05 11:06:24350 days 17 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x88ff6f5847671cbbb5ac17c7f1fbd85f7ab6cc736850d4bffc7a5a8823cba13d89269512023-05-05 10:19:30350 days 18 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x88ff6f5847671cbbb5ac17c7f1fbd85f7ab6cc736850d4bffc7a5a8823cba13d89269512023-05-05 10:19:30350 days 18 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x4d8c1ed1441806c9a6da5035430cdbe3df507573673838d74a36680c421f287f89254562023-05-05 9:29:40350 days 19 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x5f217aa7bfc492cff33026acace0cc18e754a75adb80e14cb39312d1fd2489c689252432023-05-05 9:22:34350 days 19 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x5f217aa7bfc492cff33026acace0cc18e754a75adb80e14cb39312d1fd2489c689252432023-05-05 9:22:34350 days 19 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x5f217aa7bfc492cff33026acace0cc18e754a75adb80e14cb39312d1fd2489c689252432023-05-05 9:22:34350 days 19 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x87d5a1569bed7872dc2ad58c3950a70606be19d3fce9294cd5dfb9847d5bcc6189251622023-05-05 9:19:52350 days 19 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x87d5a1569bed7872dc2ad58c3950a70606be19d3fce9294cd5dfb9847d5bcc6189251622023-05-05 9:19:52350 days 19 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x87d5a1569bed7872dc2ad58c3950a70606be19d3fce9294cd5dfb9847d5bcc6189251622023-05-05 9:19:52350 days 19 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x87d5a1569bed7872dc2ad58c3950a70606be19d3fce9294cd5dfb9847d5bcc6189251622023-05-05 9:19:52350 days 19 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
0x7e77fc499e6e10696670262451b1c5b5120c12d8c171acccf7d8507d41e7b53b89250782023-05-05 9:17:04350 days 19 hrs ago 0x6a282c7e0656c3e1dabb2fe0972e8ea2bd109fb3 0x68d8d0c1738905814c786351918986ec50bcd7b90 ETH
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
PositionalMarketManager

Compiler Version
v0.8.4+commit.c7e474f2

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 20 : PositionalMarketManager.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

// Inheritance
import "../interfaces/IPositionalMarketManager.sol";
import "../utils/proxy/solidity-0.8.0/ProxyOwned.sol";
import "../utils/proxy/solidity-0.8.0/ProxyPausable.sol";

// Libraries
import "../utils/libraries/AddressSetLib.sol";
import "../utils/libraries/DateTime.sol";
import "@openzeppelin/contracts-4.4.1/utils/math/SafeMath.sol";

// Internal references
import "./PositionalMarketFactory.sol";
import "./PositionalMarket.sol";
import "./Position.sol";
import "../interfaces/IPositionalMarket.sol";
import "../interfaces/IPriceFeed.sol";
import "../interfaces/IThalesAMM.sol";
import "@openzeppelin/contracts-4.4.1/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract PositionalMarketManager is Initializable, ProxyOwned, ProxyPausable, IPositionalMarketManager {
    /* ========== LIBRARIES ========== */

    using SafeMath for uint;
    using AddressSetLib for AddressSetLib.AddressSet;

    /* ========== TYPES ========== */

    struct Fees {
        uint poolFee;
        uint creatorFee;
    }

    struct Durations {
        uint expiryDuration;
        uint maxTimeToMaturity;
    }

    uint private constant ONE = 1e18;

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

    Durations public override durations;
    uint public override capitalRequirement;

    bool public override marketCreationEnabled;
    bool public customMarketCreationEnabled;

    bool public onlyWhitelistedAddressesCanCreateMarkets;
    mapping(address => bool) public whitelistedAddresses;

    uint public override totalDeposited;

    AddressSetLib.AddressSet internal _activeMarkets;
    AddressSetLib.AddressSet internal _maturedMarkets;

    PositionalMarketManager internal _migratingManager;

    IPriceFeed public priceFeed;
    IERC20 public sUSD;

    address public positionalMarketFactory;

    bool public needsTransformingCollateral;

    uint public timeframeBuffer;
    uint256 public priceBuffer;

    mapping(bytes32 => mapping(uint => address[])) public marketsPerOracleKey;
    mapping(address => uint) public marketsStrikePrice;

    bool public override onlyAMMMintingAndBurning;

    uint public marketCreationMonthLimit;

    uint public allowedDate1;
    uint public allowedDate2;

    mapping(bytes32 => mapping(uint => mapping(uint => address))) public marketExistsByOracleKeyDateAndStrikePrice;

    function initialize(
        address _owner,
        IERC20 _sUSD,
        IPriceFeed _priceFeed,
        uint _expiryDuration,
        uint _maxTimeToMaturity
    ) external initializer {
        setOwner(_owner);
        priceFeed = _priceFeed;
        sUSD = _sUSD;

        // Temporarily change the owner so that the setters don't revert.
        owner = msg.sender;

        marketCreationEnabled = true;
        customMarketCreationEnabled = false;
        onlyWhitelistedAddressesCanCreateMarkets = false;

        setExpiryDuration(_expiryDuration);
        setMaxTimeToMaturity(_maxTimeToMaturity);
    }

    /// @notice isKnownMarket checks if market is among matured or active markets
    /// @param candidate Address of the market.
    /// @return bool
    function isKnownMarket(address candidate) public view override returns (bool) {
        return _activeMarkets.contains(candidate) || _maturedMarkets.contains(candidate);
    }

    /// @notice isActiveMarket checks if market is active market
    /// @param candidate Address of the market.
    /// @return bool
    function isActiveMarket(address candidate) public view override returns (bool) {
        return _activeMarkets.contains(candidate);
    }

    /// @notice numActiveMarkets returns number of active markets
    /// @return uint
    function numActiveMarkets() external view override returns (uint) {
        return _activeMarkets.elements.length;
    }

    /// @notice activeMarkets returns list of active markets
    /// @param index index of the page
    /// @param pageSize number of addresses per page
    /// @return address[] active market list
    function activeMarkets(uint index, uint pageSize) external view override returns (address[] memory) {
        return _activeMarkets.getPage(index, pageSize);
    }

    /// @notice numMaturedMarkets returns number of mature markets
    /// @return uint
    function numMaturedMarkets() external view override returns (uint) {
        return _maturedMarkets.elements.length;
    }

    /// @notice maturedMarkets returns list of matured markets
    /// @param index index of the page
    /// @param pageSize number of addresses per page
    /// @return address[] matured market list
    function maturedMarkets(uint index, uint pageSize) external view override returns (address[] memory) {
        return _maturedMarkets.getPage(index, pageSize);
    }

    /// @notice incrementTotalDeposited increments totalDeposited value
    /// @param delta increment amount
    function incrementTotalDeposited(uint delta) external onlyActiveMarkets notPaused {
        totalDeposited = totalDeposited.add(delta);
    }

    /// @notice decrementTotalDeposited decrements totalDeposited value
    /// @dev As individual market debt is not tracked here, the underlying markets
    /// need to be careful never to subtract more debt than they added.
    /// This can't be enforced without additional state/communication overhead.
    /// @param delta decrement amount
    function decrementTotalDeposited(uint delta) external onlyKnownMarkets notPaused {
        totalDeposited = totalDeposited.sub(delta);
    }

    /// @notice createMarket create market function
    /// @param oracleKey market oracle key
    /// @param strikePrice market strike price
    /// @param maturity  market maturity date
    /// @param initialMint initial sUSD to mint options for
    /// @return IPositionalMarket created market
    function createMarket(
        bytes32 oracleKey,
        uint strikePrice,
        uint maturity,
        uint initialMint
    )
        external
        override
        notPaused
        returns (
            IPositionalMarket // no support for returning PositionalMarket polymorphically given the interface
        )
    {
        if (onlyWhitelistedAddressesCanCreateMarkets) {
            require(whitelistedAddresses[msg.sender], "Only whitelisted addresses can create markets");
        }

        (bool canCreate, string memory message) = canCreateMarket(oracleKey, maturity, strikePrice);
        require(canCreate, message);

        uint expiry = maturity.add(durations.expiryDuration);

        PositionalMarket market = PositionalMarketFactory(positionalMarketFactory).createMarket(
            PositionalMarketFactory.PositionCreationMarketParameters(
                msg.sender,
                sUSD,
                priceFeed,
                oracleKey,
                strikePrice,
                [maturity, expiry],
                initialMint
            )
        );

        _activeMarkets.add(address(market));

        // The debt can't be incremented in the new market's constructor because until construction is complete,
        // the manager doesn't know its address in order to grant it permission.
        totalDeposited = totalDeposited.add(initialMint);
        sUSD.transferFrom(msg.sender, address(market), _transformCollateral(initialMint));

        (IPosition up, IPosition down) = market.getOptions();

        marketExistsByOracleKeyDateAndStrikePrice[oracleKey][maturity][strikePrice] = address(market);

        emit MarketCreated(
            address(market),
            msg.sender,
            oracleKey,
            strikePrice,
            maturity,
            expiry,
            address(up),
            address(down),
            false,
            address(0)
        );
        return market;
    }

    /// @notice transferSusdTo transfers sUSD from market to receiver
    /// @dev Only to be called by markets themselves
    /// @param sender address of sender
    /// @param receiver address of receiver
    /// @param amount amount to be transferred
    function transferSusdTo(
        address sender,
        address receiver,
        uint amount
    ) external override {
        //only to be called by markets themselves
        require(isKnownMarket(address(msg.sender)), "Market unknown.");
        bool success = sUSD.transferFrom(sender, receiver, amount);
        if (!success) {
            revert("TransferFrom function failed");
        }
    }

    /// @notice resolveMarket resolves an active market
    /// @param market address of the market
    function resolveMarket(address market) external override {
        require(_activeMarkets.contains(market), "Not an active market");
        PositionalMarket(market).resolve();
        _activeMarkets.remove(market);
        _maturedMarkets.add(market);
    }

    /// @notice resolveMarketsBatch resolve all markets in the batch
    /// @param markets the batch
    function resolveMarketsBatch(address[] calldata markets) external {
        for (uint i = 0; i < markets.length; i++) {
            address market = markets[i];
            if (_activeMarkets.contains(market)) {
                PositionalMarket(market).resolve();
                _activeMarkets.remove(market);
                _maturedMarkets.add(market);
            }
        }
    }

    /// @notice expireMarkets removes expired markets from matured markets
    /// @param markets array of market addresses
    function expireMarkets(address[] calldata markets) external override notPaused onlyOwner {
        for (uint i = 0; i < markets.length; i++) {
            address market = markets[i];

            require(isKnownMarket(address(market)), "Market unknown.");

            // The market itself handles decrementing the total deposits.
            PositionalMarket(market).expire(payable(msg.sender));

            // Note that we required that the market is known, which guarantees
            // its index is defined and that the list of markets is not empty.
            _maturedMarkets.remove(market);

            emit MarketExpired(market);
        }
    }

    /// @notice transformCollateral transforms collateral
    /// @param value value to be transformed
    /// @return uint
    function transformCollateral(uint value) external view override returns (uint) {
        return _transformCollateral(value);
    }

    /// @notice reverseTransformCollateral reverse collateral if needed
    /// @param value value to be reversed
    /// @return uint
    function reverseTransformCollateral(uint value) external view override returns (uint) {
        if (needsTransformingCollateral) {
            return value * 1e12;
        } else {
            return value;
        }
    }

    /// @notice canCreateMarket checks if market can be created
    /// @param oracleKey market oracle key
    /// @param maturity market maturity timestamp
    /// @param strikePrice market strike price
    /// @return bool
    function canCreateMarket(
        bytes32 oracleKey,
        uint maturity,
        uint strikePrice
    ) public view returns (bool, string memory) {
        if (!marketCreationEnabled) {
            return (false, "Market creation is disabled");
        }

        if (!_isValidKey(oracleKey)) {
            return (false, "Invalid key");
        }

        if (maturity > block.timestamp + durations.maxTimeToMaturity) {
            return (false, "Maturity too far in the future");
        }

        if (block.timestamp >= maturity) {
            return (false, "Maturity cannot be in the past");
        }

        if (marketExistsByOracleKeyDateAndStrikePrice[oracleKey][maturity][strikePrice] != address(0)) {
            return (false, "Market already exists");
        }

        uint strikePriceStep = getStrikePriceStep(oracleKey);
        uint currentAssetPrice = priceFeed.rateForCurrency(oracleKey);

        if (strikePriceStep != 0 && strikePrice % strikePriceStep != 0) {
            return (false, "Invalid strike price");
        }

        uint dateDiff1 = (maturity - allowedDate1) % 604800;
        uint dateDiff2 = (maturity - allowedDate2) % 604800;

        if (!(dateDiff1 == 0 || dateDiff2 == 0)) {
            return (false, "Invalid maturity");
        }

        return (true, "");
    }

    /// @notice enableWhitelistedAddresses enables option that only whitelisted addresses
    /// can create markets
    function enableWhitelistedAddresses() external onlyOwner {
        onlyWhitelistedAddressesCanCreateMarkets = true;
    }

    /// @notice disableWhitelistedAddresses disables option that only whitelisted addresses
    /// can create markets
    function disableWhitelistedAddresses() external onlyOwner {
        onlyWhitelistedAddressesCanCreateMarkets = false;
    }

    /// @notice addWhitelistedAddress adds given address to whitelisted addresses list
    /// @param _address address to be added to the list
    function addWhitelistedAddress(address _address) external onlyOwner {
        whitelistedAddresses[_address] = true;
    }

    /// @notice removeWhitelistedAddress removes given address from whitelisted addresses list
    /// @param _address address to be removed from the list
    function removeWhitelistedAddress(address _address) external onlyOwner {
        delete whitelistedAddresses[_address];
    }

    /// @notice setWhitelistedAddresses enables whitelist addresses option and creates list
    /// @param _whitelistedAddresses array of whitelisted addresses
    function setWhitelistedAddresses(address[] calldata _whitelistedAddresses) external onlyOwner {
        require(_whitelistedAddresses.length > 0, "Whitelisted addresses cannot be empty");
        onlyWhitelistedAddressesCanCreateMarkets = true;
        for (uint256 index = 0; index < _whitelistedAddresses.length; index++) {
            whitelistedAddresses[_whitelistedAddresses[index]] = true;
        }
    }

    /// @notice setPositionalMarketFactory sets PositionalMarketFactory address
    /// @param _positionalMarketFactory address of PositionalMarketFactory
    function setPositionalMarketFactory(address _positionalMarketFactory) external onlyOwner {
        positionalMarketFactory = _positionalMarketFactory;
        emit SetPositionalMarketFactory(_positionalMarketFactory);
    }

    /// @notice setNeedsTransformingCollateral sets needsTransformingCollateral value
    /// @param _needsTransformingCollateral boolen value to be set
    function setNeedsTransformingCollateral(bool _needsTransformingCollateral) external onlyOwner {
        needsTransformingCollateral = _needsTransformingCollateral;
    }

    /// @notice setExpiryDuration sets expiryDuration value
    /// @param _expiryDuration value in seconds needed for market expiry check
    function setExpiryDuration(uint _expiryDuration) public onlyOwner {
        durations.expiryDuration = _expiryDuration;
        emit ExpiryDurationUpdated(_expiryDuration);
    }

    /// @notice setMaxTimeToMaturity sets maxTimeToMaturity value
    /// @param _maxTimeToMaturity value in seconds for market max time to maturity check
    function setMaxTimeToMaturity(uint _maxTimeToMaturity) public onlyOwner {
        durations.maxTimeToMaturity = _maxTimeToMaturity;
        emit MaxTimeToMaturityUpdated(_maxTimeToMaturity);
    }

    /// @notice setPriceFeed sets address of PriceFeed contract
    /// @param _address PriceFeed address
    function setPriceFeed(address _address) external onlyOwner {
        priceFeed = IPriceFeed(_address);
        emit SetPriceFeed(_address);
    }

    /// @notice setOnlyAMMMintingAndBurning whether minting and burning is only allowed for AMM
    /// @param _onlyAMMMintingAndBurning the value
    function setOnlyAMMMintingAndBurning(bool _onlyAMMMintingAndBurning) external onlyOwner {
        onlyAMMMintingAndBurning = _onlyAMMMintingAndBurning;
        emit SetOnlyAMMMintingAndBurning(_onlyAMMMintingAndBurning);
    }

    /// @notice setsUSD sets address of sUSD contract
    /// @param _address sUSD address
    function setsUSD(address _address) external onlyOwner {
        sUSD = IERC20(_address);
        emit SetsUSD(_address);
    }

    /// @notice setPriceBuffer sets priceBuffer value
    /// @param _priceBuffer value in percents needed for market creaton check
    function setPriceBuffer(uint _priceBuffer) external onlyOwner {
        priceBuffer = _priceBuffer;
        emit PriceBufferChanged(_priceBuffer);
    }

    /// @notice setTimeframeBuffer sets timeframeBuffer value
    /// @param _timeframeBuffer value in days needed for market creaton check
    function setTimeframeBuffer(uint _timeframeBuffer) external onlyOwner {
        timeframeBuffer = _timeframeBuffer;
        emit TimeframeBufferChanged(_timeframeBuffer);
    }

    /// @notice setMarketCreationEnabled sets marketCreationEnabled value
    /// @param enabled boolean value to enable/disable market creation
    function setMarketCreationEnabled(bool enabled) external onlyOwner {
        if (enabled != marketCreationEnabled) {
            marketCreationEnabled = enabled;
            emit MarketCreationEnabledUpdated(enabled);
        }
    }

    /// @notice setMarketCreationParameters sets params for market creation
    /// @param _allowedDate1 timestamp to be compared with strike date
    /// @param _allowedDate2 timestamp to be compared with strike date
    function setMarketCreationParameters(uint _allowedDate1, uint _allowedDate2) external onlyOwner {
        allowedDate1 = _allowedDate1;
        allowedDate2 = _allowedDate2;

        emit MarketCreationParametersChanged(_allowedDate1, _allowedDate2);
    }

    /// @notice getStrikePriceStep calculates strike price step
    /// @param oracleKey oracle key
    function getStrikePriceStep(bytes32 oracleKey) public view returns (uint result) {
        if (_getImpliedVolatility(oracleKey) == 0) return 0;
        uint strikePriceStep = (priceFeed.rateForCurrency(oracleKey) * _getImpliedVolatility(oracleKey)) / (2000 * ONE);

        uint exponent = _getExponent(strikePriceStep);

        uint8[3] memory indexArray = [1, 2, 3];
        uint tempMultiplier = _calculateStrikePriceStepMultiplier(strikePriceStep, exponent, exponent);

        for (uint i = 0; i < indexArray.length; i++) {
            result = _calculateStrikePriceStepValue(indexArray[i], tempMultiplier);

            if (strikePriceStep > result && i != (indexArray.length - 1)) {
                continue;
            } else if (strikePriceStep > result && i == (indexArray.length - 1)) {
                tempMultiplier = _calculateStrikePriceStepMultiplier(
                    strikePriceStep,
                    exponent + 1,
                    exponent == 0 ? exponent : exponent - 1
                );
                uint nextResult = _calculateStrikePriceStepValue(indexArray[0], tempMultiplier);
                if (strikePriceStep - result > nextResult - strikePriceStep) {
                    result = nextResult;
                }
                break;
            } else {
                uint prevResult = 0;
                if (i == 0) {
                    tempMultiplier = _calculateStrikePriceStepMultiplier(strikePriceStep, exponent - 1, exponent + 1);
                    prevResult = _calculateStrikePriceStepValue(indexArray[2], tempMultiplier);
                } else {
                    prevResult = _calculateStrikePriceStepValue(indexArray[i - 1], tempMultiplier);
                }
                if (result - strikePriceStep > strikePriceStep - prevResult) {
                    result = prevResult;
                }
                break;
            }
        }
    }

    /// @notice _calculateStrikePriceStepValue calculates strike price step via formulae
    /// @param index index value
    /// @param multiplier multiplier value
    function _calculateStrikePriceStepValue(uint index, uint multiplier) internal pure returns (uint value) {
        value = (2**index - index) * multiplier;
    }

    /// @notice _calculateStrikePriceStepValue helper function for calculating strike price step
    /// @param strikePriceStep initial strike price step
    /// @param exponent1 exponent if strikePriceStep >= 1
    /// @param exponent2 exponent if strikePriceStep < 1
    function _calculateStrikePriceStepMultiplier(
        uint strikePriceStep,
        uint exponent1,
        uint exponent2
    ) internal pure returns (uint value) {
        value = strikePriceStep >= ONE ? 10**exponent1 * ONE : ONE / (10**exponent2);
    }

    /// @notice _getExponent helper function for calculating exponent of strike price step
    /// @param strikePriceStep initial strike price step
    function _getExponent(uint strikePriceStep) internal pure returns (uint exponent) {
        if (strikePriceStep >= ONE) {
            while (strikePriceStep > ONE) {
                strikePriceStep /= 10;
                exponent += 1;
            }
            exponent -= 1;
        } else {
            while (strikePriceStep < ONE) {
                strikePriceStep *= 10;
                exponent += 1;
            }
        }
    }

    /// @notice _isValidKey checks if oracle key is supported by PriceFeed contract
    /// @param oracleKey oracle key
    /// @return bool
    function _isValidKey(bytes32 oracleKey) internal view returns (bool) {
        // If it has a rate, then it's possibly a valid key
        if (priceFeed.rateForCurrency(oracleKey) != 0) {
            return true;
        }

        return false;
    }

    /// @notice _getImpliedVolatility gets implied volatility per asset from ThalesAMM contract
    /// @param oracleKey asset to fetch value for
    /// @return impliedVolatility
    function _getImpliedVolatility(bytes32 oracleKey) internal view returns (uint impliedVolatility) {
        address thalesAMM = PositionalMarketFactory(positionalMarketFactory).thalesAMM();
        impliedVolatility = IThalesAMM(thalesAMM).impliedVolatilityPerAsset(oracleKey);
    }

    /// @notice get the thales amm address from the factory
    /// @return thales amm address
    function getThalesAMM() external view override returns (address) {
        return PositionalMarketFactory(positionalMarketFactory).thalesAMM();
    }

    /// @notice _transformCollateral transforms collateral if needed
    /// @param value value to be transformed
    /// @return uint
    function _transformCollateral(uint value) internal view returns (uint) {
        if (needsTransformingCollateral) {
            return value / 1e12;
        } else {
            return value;
        }
    }

    modifier onlyActiveMarkets() {
        require(_activeMarkets.contains(msg.sender), "Permitted only for active markets.");
        _;
    }

    modifier onlyKnownMarkets() {
        require(isKnownMarket(msg.sender), "Permitted only for known markets.");
        _;
    }

    event MarketCreated(
        address market,
        address indexed creator,
        bytes32 indexed oracleKey,
        uint strikePrice,
        uint maturityDate,
        uint expiryDate,
        address up,
        address down,
        bool customMarket,
        address customOracle
    );
    event MarketExpired(address market);
    event MarketsMigrated(PositionalMarketManager receivingManager, PositionalMarket[] markets);
    event MarketsReceived(PositionalMarketManager migratingManager, PositionalMarket[] markets);
    event MarketCreationEnabledUpdated(bool enabled);
    event ExpiryDurationUpdated(uint duration);
    event MaxTimeToMaturityUpdated(uint duration);
    event SetPositionalMarketFactory(address _positionalMarketFactory);
    event SetZeroExAddress(address _zeroExAddress);
    event SetPriceFeed(address _address);
    event SetsUSD(address _address);
    event SetMigratingManager(address manager);
    event PriceBufferChanged(uint priceBuffer);
    event TimeframeBufferChanged(uint timeframeBuffer);
    event SetOnlyAMMMintingAndBurning(bool _SetOnlyAMMMintingAndBurning);
    event MarketCreationParametersChanged(uint _allowedDate1, uint _allowedDate2);
}

File 2 of 20 : 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 3 of 20 : 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 4 of 20 : ProxyPausable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

// Inheritance
import "./ProxyOwned.sol";

// Clone of syntetix contract without constructor

contract ProxyPausable is ProxyOwned {
    uint public lastPauseTime;
    bool public paused;

    

    /**
     * @notice Change the paused state of the contract
     * @dev Only the contract owner may call this.
     */
    function setPaused(bool _paused) external onlyOwner {
        // Ensure we're actually changing the state before we do anything
        if (_paused == paused) {
            return;
        }

        // Set our paused state.
        paused = _paused;

        // If applicable, set the last pause time.
        if (paused) {
            lastPauseTime = block.timestamp;
        }

        // Let everyone know that our pause state has changed.
        emit PauseChanged(paused);
    }

    event PauseChanged(bool isPaused);

    modifier notPaused {
        require(!paused, "This action cannot be performed while the contract is paused");
        _;
    }
}

File 5 of 20 : AddressSetLib.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

library AddressSetLib {
    struct AddressSet {
        address[] elements;
        mapping(address => uint) indices;
    }

    function contains(AddressSet storage set, address candidate) internal view returns (bool) {
        if (set.elements.length == 0) {
            return false;
        }
        uint index = set.indices[candidate];
        return index != 0 || set.elements[0] == candidate;
    }

    function getPage(
        AddressSet storage set,
        uint index,
        uint pageSize
    ) internal view returns (address[] memory) {
        // NOTE: This implementation should be converted to slice operators if the compiler is updated to v0.6.0+
        uint endIndex = index + pageSize; // The check below that endIndex <= index handles overflow.

        // If the page extends past the end of the list, truncate it.
        if (endIndex > set.elements.length) {
            endIndex = set.elements.length;
        }
        if (endIndex <= index) {
            return new address[](0);
        }

        uint n = endIndex - index; // We already checked for negative overflow.
        address[] memory page = new address[](n);
        for (uint i; i < n; i++) {
            page[i] = set.elements[i + index];
        }
        return page;
    }

    function add(AddressSet storage set, address element) internal {
        // Adding to a set is an idempotent operation.
        if (!contains(set, element)) {
            set.indices[element] = set.elements.length;
            set.elements.push(element);
        }
    }

    function remove(AddressSet storage set, address element) internal {
        require(contains(set, element), "Element not in set.");
        // Replace the removed element with the last element of the list.
        uint index = set.indices[element];
        uint lastIndex = set.elements.length - 1; // We required that element is in the list, so it is not empty.
        if (index != lastIndex) {
            // No need to shift the last element if it is the one we want to delete.
            address shiftedElement = set.elements[lastIndex];
            set.elements[index] = shiftedElement;
            set.indices[shiftedElement] = index;
        }
        set.elements.pop();
        delete set.indices[element];
    }
}

File 6 of 20 : DateTime.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// ----------------------------------------------------------------------------
// DateTime Library v2.0
//
// A gas-efficient Solidity date and time library
//
// https://github.com/bokkypoobah/BokkyPooBahsDateTimeLibrary
//
// Tested date range 1970/01/01 to 2345/12/31
//
// Conventions:
// Unit      | Range         | Notes
// :-------- |:-------------:|:-----
// timestamp | >= 0          | Unix timestamp, number of seconds since 1970/01/01 00:00:00 UTC
// year      | 1970 ... 2345 |
// month     | 1 ... 12      |
// day       | 1 ... 31      |
// hour      | 0 ... 23      |
// minute    | 0 ... 59      |
// second    | 0 ... 59      |
// dayOfWeek | 1 ... 7       | 1 = Monday, ..., 7 = Sunday
//
//
// Enjoy. (c) BokkyPooBah / Bok Consulting Pty Ltd 2018-2019. The MIT Licence.
// ----------------------------------------------------------------------------

library DateTime {
    uint256 constant SECONDS_PER_DAY = 24 * 60 * 60;
    uint256 constant SECONDS_PER_HOUR = 60 * 60;
    uint256 constant SECONDS_PER_MINUTE = 60;
    int256 constant OFFSET19700101 = 2440588;

    uint256 constant DOW_MON = 1;
    uint256 constant DOW_TUE = 2;
    uint256 constant DOW_WED = 3;
    uint256 constant DOW_THU = 4;
    uint256 constant DOW_FRI = 5;
    uint256 constant DOW_SAT = 6;
    uint256 constant DOW_SUN = 7;

    // ------------------------------------------------------------------------
    // Calculate the number of days from 1970/01/01 to year/month/day using
    // the date conversion algorithm from
    //   http://aa.usno.navy.mil/faq/docs/JD_Formula.php
    // and subtracting the offset 2440588 so that 1970/01/01 is day 0
    //
    // days = day
    //      - 32075
    //      + 1461 * (year + 4800 + (month - 14) / 12) / 4
    //      + 367 * (month - 2 - (month - 14) / 12 * 12) / 12
    //      - 3 * ((year + 4900 + (month - 14) / 12) / 100) / 4
    //      - offset
    // ------------------------------------------------------------------------
    function _daysFromDate(
        uint256 year,
        uint256 month,
        uint256 day
    ) internal pure returns (uint256 _days) {
        require(year >= 1970);
        int256 _year = int256(year);
        int256 _month = int256(month);
        int256 _day = int256(day);

        int256 __days =
            _day -
                32075 +
                (1461 * (_year + 4800 + (_month - 14) / 12)) /
                4 +
                (367 * (_month - 2 - ((_month - 14) / 12) * 12)) /
                12 -
                (3 * ((_year + 4900 + (_month - 14) / 12) / 100)) /
                4 -
                OFFSET19700101;

        _days = uint256(__days);
    }

    // ------------------------------------------------------------------------
    // Calculate year/month/day from the number of days since 1970/01/01 using
    // the date conversion algorithm from
    //   http://aa.usno.navy.mil/faq/docs/JD_Formula.php
    // and adding the offset 2440588 so that 1970/01/01 is day 0
    //
    // int L = days + 68569 + offset
    // int N = 4 * L / 146097
    // L = L - (146097 * N + 3) / 4
    // year = 4000 * (L + 1) / 1461001
    // L = L - 1461 * year / 4 + 31
    // month = 80 * L / 2447
    // dd = L - 2447 * month / 80
    // L = month / 11
    // month = month + 2 - 12 * L
    // year = 100 * (N - 49) + year + L
    // ------------------------------------------------------------------------
    function _daysToDate(uint256 _days)
        internal
        pure
        returns (
            uint256 year,
            uint256 month,
            uint256 day
        )
    {
        int256 __days = int256(_days);

        int256 L = __days + 68569 + OFFSET19700101;
        int256 N = (4 * L) / 146097;
        L = L - (146097 * N + 3) / 4;
        int256 _year = (4000 * (L + 1)) / 1461001;
        L = L - (1461 * _year) / 4 + 31;
        int256 _month = (80 * L) / 2447;
        int256 _day = L - (2447 * _month) / 80;
        L = _month / 11;
        _month = _month + 2 - 12 * L;
        _year = 100 * (N - 49) + _year + L;

        year = uint256(_year);
        month = uint256(_month);
        day = uint256(_day);
    }

    function timestampFromDate(
        uint256 year,
        uint256 month,
        uint256 day
    ) internal pure returns (uint256 timestamp) {
        timestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY;
    }

    function timestampFromDateTime(
        uint256 year,
        uint256 month,
        uint256 day,
        uint256 hour,
        uint256 minute,
        uint256 second
    ) internal pure returns (uint256 timestamp) {
        timestamp =
            _daysFromDate(year, month, day) *
            SECONDS_PER_DAY +
            hour *
            SECONDS_PER_HOUR +
            minute *
            SECONDS_PER_MINUTE +
            second;
    }

    function timestampToDate(uint256 timestamp)
        internal
        pure
        returns (
            uint256 year,
            uint256 month,
            uint256 day
        )
    {
        (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY);
    }

    function timestampToDateTime(uint256 timestamp)
        internal
        pure
        returns (
            uint256 year,
            uint256 month,
            uint256 day,
            uint256 hour,
            uint256 minute,
            uint256 second
        )
    {
        (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY);
        uint256 secs = timestamp % SECONDS_PER_DAY;
        hour = secs / SECONDS_PER_HOUR;
        secs = secs % SECONDS_PER_HOUR;
        minute = secs / SECONDS_PER_MINUTE;
        second = secs % SECONDS_PER_MINUTE;
    }

    function isValidDate(
        uint256 year,
        uint256 month,
        uint256 day
    ) internal pure returns (bool valid) {
        if (year >= 1970 && month > 0 && month <= 12) {
            uint256 daysInMonth = _getDaysInMonth(year, month);
            if (day > 0 && day <= daysInMonth) {
                valid = true;
            }
        }
    }

    function isValidDateTime(
        uint256 year,
        uint256 month,
        uint256 day,
        uint256 hour,
        uint256 minute,
        uint256 second
    ) internal pure returns (bool valid) {
        if (isValidDate(year, month, day)) {
            if (hour < 24 && minute < 60 && second < 60) {
                valid = true;
            }
        }
    }

    function isLeapYear(uint256 timestamp)
        internal
        pure
        returns (bool leapYear)
    {
        (uint256 year, , ) = _daysToDate(timestamp / SECONDS_PER_DAY);
        leapYear = _isLeapYear(year);
    }

    function _isLeapYear(uint256 year) internal pure returns (bool leapYear) {
        leapYear = ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
    }

    function isWeekDay(uint256 timestamp) internal pure returns (bool weekDay) {
        weekDay = getDayOfWeek(timestamp) <= DOW_FRI;
    }

    function isWeekEnd(uint256 timestamp) internal pure returns (bool weekEnd) {
        weekEnd = getDayOfWeek(timestamp) >= DOW_SAT;
    }

    function getDaysInMonth(uint256 timestamp)
        internal
        pure
        returns (uint256 daysInMonth)
    {
        (uint256 year, uint256 month, ) =
            _daysToDate(timestamp / SECONDS_PER_DAY);
        daysInMonth = _getDaysInMonth(year, month);
    }

    function _getDaysInMonth(uint256 year, uint256 month)
        internal
        pure
        returns (uint256 daysInMonth)
    {
        if (
            month == 1 ||
            month == 3 ||
            month == 5 ||
            month == 7 ||
            month == 8 ||
            month == 10 ||
            month == 12
        ) {
            daysInMonth = 31;
        } else if (month != 2) {
            daysInMonth = 30;
        } else {
            daysInMonth = _isLeapYear(year) ? 29 : 28;
        }
    }

    // 1 = Monday, 7 = Sunday
    function getDayOfWeek(uint256 timestamp)
        internal
        pure
        returns (uint256 dayOfWeek)
    {
        uint256 _days = timestamp / SECONDS_PER_DAY;
        dayOfWeek = ((_days + 3) % 7) + 1;
    }

    function getYear(uint256 timestamp) internal pure returns (uint256 year) {
        (year, , ) = _daysToDate(timestamp / SECONDS_PER_DAY);
    }

    function getMonth(uint256 timestamp) internal pure returns (uint256 month) {
        (, month, ) = _daysToDate(timestamp / SECONDS_PER_DAY);
    }

    function getDay(uint256 timestamp) internal pure returns (uint256 day) {
        (, , day) = _daysToDate(timestamp / SECONDS_PER_DAY);
    }

    function getHour(uint256 timestamp) internal pure returns (uint256 hour) {
        uint256 secs = timestamp % SECONDS_PER_DAY;
        hour = secs / SECONDS_PER_HOUR;
    }

    function getMinute(uint256 timestamp)
        internal
        pure
        returns (uint256 minute)
    {
        uint256 secs = timestamp % SECONDS_PER_HOUR;
        minute = secs / SECONDS_PER_MINUTE;
    }

    function getSecond(uint256 timestamp)
        internal
        pure
        returns (uint256 second)
    {
        second = timestamp % SECONDS_PER_MINUTE;
    }

    function addYears(uint256 timestamp, uint256 _years)
        internal
        pure
        returns (uint256 newTimestamp)
    {
        (uint256 year, uint256 month, uint256 day) =
            _daysToDate(timestamp / SECONDS_PER_DAY);
        year += _years;
        uint256 daysInMonth = _getDaysInMonth(year, month);
        if (day > daysInMonth) {
            day = daysInMonth;
        }
        newTimestamp =
            _daysFromDate(year, month, day) *
            SECONDS_PER_DAY +
            (timestamp % SECONDS_PER_DAY);
        require(newTimestamp >= timestamp);
    }

    function addMonths(uint256 timestamp, uint256 _months)
        internal
        pure
        returns (uint256 newTimestamp)
    {
        (uint256 year, uint256 month, uint256 day) =
            _daysToDate(timestamp / SECONDS_PER_DAY);
        month += _months;
        year += (month - 1) / 12;
        month = ((month - 1) % 12) + 1;
        uint256 daysInMonth = _getDaysInMonth(year, month);
        if (day > daysInMonth) {
            day = daysInMonth;
        }
        newTimestamp =
            _daysFromDate(year, month, day) *
            SECONDS_PER_DAY +
            (timestamp % SECONDS_PER_DAY);
        require(newTimestamp >= timestamp);
    }

    function addDays(uint256 timestamp, uint256 _days)
        internal
        pure
        returns (uint256 newTimestamp)
    {
        newTimestamp = timestamp + _days * SECONDS_PER_DAY;
        require(newTimestamp >= timestamp);
    }

    function addHours(uint256 timestamp, uint256 _hours)
        internal
        pure
        returns (uint256 newTimestamp)
    {
        newTimestamp = timestamp + _hours * SECONDS_PER_HOUR;
        require(newTimestamp >= timestamp);
    }

    function addMinutes(uint256 timestamp, uint256 _minutes)
        internal
        pure
        returns (uint256 newTimestamp)
    {
        newTimestamp = timestamp + _minutes * SECONDS_PER_MINUTE;
        require(newTimestamp >= timestamp);
    }

    function addSeconds(uint256 timestamp, uint256 _seconds)
        internal
        pure
        returns (uint256 newTimestamp)
    {
        newTimestamp = timestamp + _seconds;
        require(newTimestamp >= timestamp);
    }

    function subYears(uint256 timestamp, uint256 _years)
        internal
        pure
        returns (uint256 newTimestamp)
    {
        (uint256 year, uint256 month, uint256 day) =
            _daysToDate(timestamp / SECONDS_PER_DAY);
        year -= _years;
        uint256 daysInMonth = _getDaysInMonth(year, month);
        if (day > daysInMonth) {
            day = daysInMonth;
        }
        newTimestamp =
            _daysFromDate(year, month, day) *
            SECONDS_PER_DAY +
            (timestamp % SECONDS_PER_DAY);
        require(newTimestamp <= timestamp);
    }

    function subMonths(uint256 timestamp, uint256 _months)
        internal
        pure
        returns (uint256 newTimestamp)
    {
        (uint256 year, uint256 month, uint256 day) =
            _daysToDate(timestamp / SECONDS_PER_DAY);
        uint256 yearMonth = year * 12 + (month - 1) - _months;
        year = yearMonth / 12;
        month = (yearMonth % 12) + 1;
        uint256 daysInMonth = _getDaysInMonth(year, month);
        if (day > daysInMonth) {
            day = daysInMonth;
        }
        newTimestamp =
            _daysFromDate(year, month, day) *
            SECONDS_PER_DAY +
            (timestamp % SECONDS_PER_DAY);
        require(newTimestamp <= timestamp);
    }

    function subDays(uint256 timestamp, uint256 _days)
        internal
        pure
        returns (uint256 newTimestamp)
    {
        newTimestamp = timestamp - _days * SECONDS_PER_DAY;
        require(newTimestamp <= timestamp);
    }

    function subHours(uint256 timestamp, uint256 _hours)
        internal
        pure
        returns (uint256 newTimestamp)
    {
        newTimestamp = timestamp - _hours * SECONDS_PER_HOUR;
        require(newTimestamp <= timestamp);
    }

    function subMinutes(uint256 timestamp, uint256 _minutes)
        internal
        pure
        returns (uint256 newTimestamp)
    {
        newTimestamp = timestamp - _minutes * SECONDS_PER_MINUTE;
        require(newTimestamp <= timestamp);
    }

    function subSeconds(uint256 timestamp, uint256 _seconds)
        internal
        pure
        returns (uint256 newTimestamp)
    {
        newTimestamp = timestamp - _seconds;
        require(newTimestamp <= timestamp);
    }

    function diffYears(uint256 fromTimestamp, uint256 toTimestamp)
        internal
        pure
        returns (uint256 _years)
    {
        require(fromTimestamp <= toTimestamp);
        (uint256 fromYear, , ) = _daysToDate(fromTimestamp / SECONDS_PER_DAY);
        (uint256 toYear, , ) = _daysToDate(toTimestamp / SECONDS_PER_DAY);
        _years = toYear - fromYear;
    }

    function diffMonths(uint256 fromTimestamp, uint256 toTimestamp)
        internal
        pure
        returns (uint256 _months)
    {
        require(fromTimestamp <= toTimestamp);
        (uint256 fromYear, uint256 fromMonth, ) =
            _daysToDate(fromTimestamp / SECONDS_PER_DAY);
        (uint256 toYear, uint256 toMonth, ) =
            _daysToDate(toTimestamp / SECONDS_PER_DAY);
        _months = toYear * 12 + toMonth - fromYear * 12 - fromMonth;
    }

    function diffDays(uint256 fromTimestamp, uint256 toTimestamp)
        internal
        pure
        returns (uint256 _days)
    {
        require(fromTimestamp <= toTimestamp);
        _days = (toTimestamp - fromTimestamp) / SECONDS_PER_DAY;
    }

    function diffHours(uint256 fromTimestamp, uint256 toTimestamp)
        internal
        pure
        returns (uint256 _hours)
    {
        require(fromTimestamp <= toTimestamp);
        _hours = (toTimestamp - fromTimestamp) / SECONDS_PER_HOUR;
    }

    function diffMinutes(uint256 fromTimestamp, uint256 toTimestamp)
        internal
        pure
        returns (uint256 _minutes)
    {
        require(fromTimestamp <= toTimestamp);
        _minutes = (toTimestamp - fromTimestamp) / SECONDS_PER_MINUTE;
    }

    function diffSeconds(uint256 fromTimestamp, uint256 toTimestamp)
        internal
        pure
        returns (uint256 _seconds)
    {
        require(fromTimestamp <= toTimestamp);
        _seconds = toTimestamp - fromTimestamp;
    }
}

File 7 of 20 : SafeMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

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

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

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

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

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

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

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

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

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

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

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

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

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

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

File 8 of 20 : PositionalMarketFactory.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

// Inheritance
import "../utils/proxy/solidity-0.8.0/ProxyOwned.sol";

// Internal references
import "./Position.sol";
import "./PositionalMarket.sol";
import "./PositionalMarketFactory.sol";
import "../interfaces/IPriceFeed.sol";
import "../interfaces/IPositionalMarket.sol";
import "@openzeppelin/contracts-4.4.1/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts-4.4.1/proxy/Clones.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract PositionalMarketFactory is Initializable, ProxyOwned {
    /* ========== STATE VARIABLES ========== */
    address public positionalMarketManager;

    address public positionalMarketMastercopy;
    address public positionMastercopy;

    address public limitOrderProvider;
    address public thalesAMM;

    struct PositionCreationMarketParameters {
        address creator;
        IERC20 _sUSD;
        IPriceFeed _priceFeed;
        bytes32 oracleKey;
        uint strikePrice;
        uint[2] times; // [maturity, expiry]
        uint initialMint;
    }

    function initialize(address _owner) external initializer {
        setOwner(_owner);
    }

    /// @notice createMarket create market function
    /// @param _parameters PositionCreationMarketParameters needed for market creation
    /// @return PositionalMarket created market
    function createMarket(PositionCreationMarketParameters calldata _parameters) external returns (PositionalMarket) {
        require(positionalMarketManager == msg.sender, "Only permitted by the manager.");

        PositionalMarket pom = PositionalMarket(Clones.clone(positionalMarketMastercopy));
        Position up = Position(Clones.clone(positionMastercopy));
        Position down = Position(Clones.clone(positionMastercopy));
        pom.initialize(
            PositionalMarket.PositionalMarketParameters(
                positionalMarketManager,
                _parameters._sUSD,
                _parameters._priceFeed,
                _parameters.creator,
                _parameters.oracleKey,
                _parameters.strikePrice,
                _parameters.times,
                _parameters.initialMint,
                address(up),
                address(down),
                thalesAMM
            )
        );
        emit MarketCreated(
            address(pom),
            _parameters.oracleKey,
            _parameters.strikePrice,
            _parameters.times[0],
            _parameters.times[1],
            _parameters.initialMint
        );
        return pom;
    }

    /// @notice setPositionalMarketManager sets positionalMarketManager value
    /// @param _positionalMarketManager address of the PositionalMarketManager contract
    function setPositionalMarketManager(address _positionalMarketManager) external onlyOwner {
        positionalMarketManager = _positionalMarketManager;
        emit PositionalMarketManagerChanged(_positionalMarketManager);
    }

    /// @notice setPositionalMarketMastercopy sets positionalMarketMastercopy value
    /// @param _positionalMarketMastercopy address of the PositionalMarketMastercopy contract
    function setPositionalMarketMastercopy(address _positionalMarketMastercopy) external onlyOwner {
        positionalMarketMastercopy = _positionalMarketMastercopy;
        emit PositionalMarketMastercopyChanged(_positionalMarketMastercopy);
    }

    /// @notice setPositionMastercopy sets positionMastercopy value
    /// @param _positionMastercopy address of the PositionMastercopy contract
    function setPositionMastercopy(address _positionMastercopy) external onlyOwner {
        positionMastercopy = _positionMastercopy;
        emit PositionMastercopyChanged(_positionMastercopy);
    }

    /// @notice setThalesAMM sets thalesAMM value
    /// @param _thalesAMM address of ThalesAMM contract
    function setThalesAMM(address _thalesAMM) external onlyOwner {
        thalesAMM = _thalesAMM;
        emit SetThalesAMM(_thalesAMM);
    }

    event PositionalMarketManagerChanged(address _positionalMarketManager);
    event PositionalMarketMastercopyChanged(address _positionalMarketMastercopy);
    event PositionMastercopyChanged(address _positionMastercopy);
    event SetThalesAMM(address _thalesAMM);
    event MarketCreated(
        address market,
        bytes32 indexed oracleKey,
        uint strikePrice,
        uint maturityDate,
        uint expiryDate,
        uint initialMint
    );
}

File 9 of 20 : PositionalMarket.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

// Inheritance
import "../OwnedWithInit.sol";
import "../interfaces/IPositionalMarket.sol";
import "../interfaces/IOracleInstance.sol";

// Libraries
import "@openzeppelin/contracts-4.4.1/utils/math/SafeMath.sol";

// Internal references
import "./PositionalMarketManager.sol";
import "./Position.sol";
import "@openzeppelin/contracts-4.4.1/token/ERC20/IERC20.sol";

contract PositionalMarket is OwnedWithInit, IPositionalMarket {
    /* ========== LIBRARIES ========== */

    using SafeMath for uint;

    /* ========== TYPES ========== */

    struct Options {
        Position up;
        Position down;
    }

    struct Times {
        uint maturity;
        uint expiry;
    }

    struct OracleDetails {
        bytes32 key;
        uint strikePrice;
        uint finalPrice;
        bool customMarket;
        address iOracleInstanceAddress;
    }

    struct PositionalMarketParameters {
        address owner;
        IERC20 sUSD;
        IPriceFeed priceFeed;
        address creator;
        bytes32 oracleKey;
        uint strikePrice;
        uint[2] times; // [maturity, expiry]
        uint deposit; // sUSD deposit
        address up;
        address down;
        address thalesAMM;
    }

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

    Options public options;
    Times public override times;
    OracleDetails public oracleDetails;
    PositionalMarketManager.Fees public override fees;
    IPriceFeed public priceFeed;
    IERC20 public sUSD;

    // `deposited` tracks the sum of all deposits.
    // This must explicitly be kept, in case tokens are transferred to the contract directly.
    uint public override deposited;
    uint public initialMint;
    address public override creator;
    bool public override resolved;

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

    bool public initialized = false;

    function initialize(PositionalMarketParameters calldata _parameters) external {
        require(!initialized, "Positional Market already initialized");
        initialized = true;
        initOwner(_parameters.owner);
        sUSD = _parameters.sUSD;
        priceFeed = _parameters.priceFeed;
        creator = _parameters.creator;

        oracleDetails = OracleDetails(_parameters.oracleKey, _parameters.strikePrice, 0, false, address(0));

        times = Times(_parameters.times[0], _parameters.times[1]);

        deposited = _parameters.deposit;
        initialMint = _parameters.deposit;

        // Instantiate the options themselves
        options.up = Position(_parameters.up);
        options.down = Position(_parameters.down);

        options.up.initialize("Position Up", "UP", _parameters.thalesAMM);
        options.down.initialize("Position Down", "DOWN", _parameters.thalesAMM);
        if (initialMint > 0) {
            require(
                !_manager().onlyAMMMintingAndBurning() || msg.sender == _manager().getThalesAMM(),
                "Only allowed from ThalesAMM"
            );
            _mint(creator, initialMint);
        }

        // Note: the ERC20 base contract does not have a constructor, so we do not have to worry
        // about initializing its state separately
    }

    /// @notice phase returns market phase
    /// @return Phase
    function phase() external view override returns (Phase) {
        if (!_matured()) {
            return Phase.Trading;
        }
        if (!_expired()) {
            return Phase.Maturity;
        }
        return Phase.Expiry;
    }

    /// @notice oraclePriceAndTimestamp returns oracle key price and last updated timestamp
    /// @return price updatedAt
    function oraclePriceAndTimestamp() external view override returns (uint price, uint updatedAt) {
        return _oraclePriceAndTimestamp();
    }

    /// @notice oraclePrice returns oracle key price
    /// @return price
    function oraclePrice() external view override returns (uint price) {
        return _oraclePrice();
    }

    /// @notice canResolve checks if market can be resolved
    /// @return bool
    function canResolve() public view override returns (bool) {
        return !resolved && _matured();
    }

    /// @notice result calculates market result based on market strike price
    /// @return Side
    function result() external view override returns (Side) {
        return _result();
    }

    /// @notice balancesOf returns balances of an account
    /// @return up down
    function balancesOf(address account) external view override returns (uint up, uint down) {
        return _balancesOf(account);
    }

    /// @notice totalSupplies returns total supplies of op and down options
    /// @return up down
    function totalSupplies() external view override returns (uint up, uint down) {
        return (options.up.totalSupply(), options.down.totalSupply());
    }

    /// @notice getMaximumBurnable returns maximum burnable amount of an account
    /// @param account address of the account
    /// @return amount
    function getMaximumBurnable(address account) external view override returns (uint amount) {
        return _getMaximumBurnable(account);
    }

    /// @notice getOptions returns up and down positions
    /// @return up down
    function getOptions() external view override returns (IPosition up, IPosition down) {
        up = options.up;
        down = options.down;
    }

    /// @notice getOracleDetails returns data from oracle source
    /// @return key strikePrice finalPrice
    function getOracleDetails()
        external
        view
        override
        returns (
            bytes32 key,
            uint strikePrice,
            uint finalPrice
        )
    {
        key = oracleDetails.key;
        strikePrice = oracleDetails.strikePrice;
        finalPrice = oracleDetails.finalPrice;
    }

    /// @notice requireUnpaused ensures that manager is not paused
    function requireUnpaused() external view {
        _requireManagerNotPaused();
    }

    /// @notice mint mints up and down tokens
    /// @param value to mint options for
    function mint(uint value) external override duringMinting {
        require(
            !_manager().onlyAMMMintingAndBurning() || msg.sender == _manager().getThalesAMM(),
            "Only allowed from ThalesAMM"
        );
        if (value == 0) {
            return;
        }

        _mint(msg.sender, value);

        _incrementDeposited(value);
        _manager().transferSusdTo(msg.sender, address(this), _manager().transformCollateral(value));
    }

    /// @notice burnOptionsMaximum burns option tokens based on maximum burnable account amount
    function burnOptionsMaximum() external override {
        require(
            !_manager().onlyAMMMintingAndBurning() || msg.sender == _manager().getThalesAMM(),
            "Only allowed from ThalesAMM"
        );
        _burnOptions(msg.sender, _getMaximumBurnable(msg.sender));
    }

    /// @notice burnOptions burns option tokens based on amount
    function burnOptions(uint amount) external override {
        require(
            !_manager().onlyAMMMintingAndBurning() || msg.sender == _manager().getThalesAMM(),
            "Only allowed from ThalesAMM"
        );
        _burnOptions(msg.sender, amount);
    }

    /// @notice resolve function for resolving market if possible
    function resolve() external onlyOwner afterMaturity managerNotPaused {
        require(canResolve(), "Can not resolve market");
        uint price;
        uint updatedAt;

        (price, updatedAt) = _oraclePriceAndTimestamp();
        oracleDetails.finalPrice = price;

        resolved = true;

        emit MarketResolved(_result(), price, updatedAt, deposited, 0, 0);
    }

    /// @notice exerciseOptions is used for exercising options from resolved market
    function exerciseOptions() external override afterMaturity returns (uint) {
        // The market must be resolved if it has not been.
        if (!resolved) {
            _manager().resolveMarket(address(this));
        }

        // If the account holds no options, revert.
        (uint upBalance, uint downBalance) = _balancesOf(msg.sender);
        require(upBalance != 0 || downBalance != 0, "Nothing to exercise");

        // Each option only needs to be exercised if the account holds any of it.
        if (upBalance != 0) {
            options.up.exercise(msg.sender);
        }
        if (downBalance != 0) {
            options.down.exercise(msg.sender);
        }

        // Only pay out the side that won.
        uint payout = (_result() == Side.Up) ? upBalance : downBalance;
        emit OptionsExercised(msg.sender, payout);
        if (payout != 0) {
            _decrementDeposited(payout);
            sUSD.transfer(msg.sender, _manager().transformCollateral(payout));
        }
        return payout;
    }

    /// @notice expire is used for exercising options from resolved market
    function expire(address payable beneficiary) external onlyOwner {
        require(_expired(), "Unexpired options remaining");
        emit Expired(beneficiary);
        _selfDestruct(beneficiary);
    }

    /// @notice _priceFeed internal function returns PriceFeed contract address
    /// @return IPriceFeed
    function _priceFeed() internal view returns (IPriceFeed) {
        return priceFeed;
    }

    /// @notice _manager internal function returns PositionalMarketManager contract address
    /// @return PositionalMarketManager
    function _manager() internal view returns (PositionalMarketManager) {
        return PositionalMarketManager(owner);
    }

    /// @notice _matured internal function checks if market is matured
    /// @return bool
    function _matured() internal view returns (bool) {
        return times.maturity < block.timestamp;
    }

    /// @notice _expired internal function checks if market is expired
    /// @return bool
    function _expired() internal view returns (bool) {
        return resolved && (times.expiry < block.timestamp || deposited == 0);
    }

    /// @notice _oraclePrice internal function returns oracle key price from source
    /// @return price
    function _oraclePrice() internal view returns (uint price) {
        return _priceFeed().rateForCurrency(oracleDetails.key);
    }

    /// @notice _oraclePriceAndTimestamp internal function returns oracle key price and last updated timestamp from source
    /// @return price updatedAt
    function _oraclePriceAndTimestamp() internal view returns (uint price, uint updatedAt) {
        return _priceFeed().rateAndUpdatedTime(oracleDetails.key);
    }

    /// @notice _result internal function calculates market result based on market strike price
    /// @return Side
    function _result() internal view returns (Side) {
        uint price;
        if (resolved) {
            price = oracleDetails.finalPrice;
        } else {
            price = _oraclePrice();
        }

        return oracleDetails.strikePrice <= price ? Side.Up : Side.Down;
    }

    /// @notice _balancesOf internal function gets account balances of up and down tokens
    /// @param account address of an account
    /// @return up down
    function _balancesOf(address account) internal view returns (uint up, uint down) {
        return (options.up.getBalanceOf(account), options.down.getBalanceOf(account));
    }

    /// @notice _getMaximumBurnable internal function gets account maximum burnable amount
    /// @param account address of an account
    /// @return amount
    function _getMaximumBurnable(address account) internal view returns (uint amount) {
        (uint upBalance, uint downBalance) = _balancesOf(account);
        return (upBalance > downBalance) ? downBalance : upBalance;
    }

    /// @notice _incrementDeposited internal function increments deposited value
    /// @param value increment value
    /// @return _deposited
    function _incrementDeposited(uint value) internal returns (uint _deposited) {
        _deposited = deposited.add(value);
        deposited = _deposited;
        _manager().incrementTotalDeposited(value);
    }

    /// @notice _decrementDeposited internal function decrements deposited value
    /// @param value decrement value
    /// @return _deposited
    function _decrementDeposited(uint value) internal returns (uint _deposited) {
        _deposited = deposited.sub(value);
        deposited = _deposited;
        _manager().decrementTotalDeposited(value);
    }

    /// @notice _requireManagerNotPaused internal function ensures that manager is not paused
    function _requireManagerNotPaused() internal view {
        require(!_manager().paused(), "This action cannot be performed while the contract is paused");
    }

    /// @notice _mint internal function mints up and down tokens
    /// @param amount value to mint options for
    function _mint(address minter, uint amount) internal {
        options.up.mint(minter, amount);
        options.down.mint(minter, amount);

        emit Mint(Side.Up, minter, amount);
        emit Mint(Side.Down, minter, amount);
    }

    /// @notice _burnOptions internal function for burning up and down tokens
    /// @param account address of an account
    /// @param amount burning amount
    function _burnOptions(address account, uint amount) internal {
        require(amount > 0, "Can not burn zero amount!");
        require(_getMaximumBurnable(account) >= amount, "There is not enough options!");

        // decrease deposit
        _decrementDeposited(amount);

        // decrease up and down options
        options.up.exerciseWithAmount(account, amount);
        options.down.exerciseWithAmount(account, amount);

        // transfer balance
        sUSD.transfer(account, _manager().transformCollateral(amount));

        // emit events
        emit OptionsBurned(account, amount);
    }

    /// @notice _selfDestruct internal function for market self desctruct
    /// @param beneficiary address of a market
    function _selfDestruct(address payable beneficiary) internal {
        uint _deposited = deposited;
        if (_deposited != 0) {
            _decrementDeposited(_deposited);
        }

        // Transfer the balance rather than the deposit value in case there are any synths left over
        // from direct transfers.
        uint balance = sUSD.balanceOf(address(this));
        if (balance != 0) {
            sUSD.transfer(beneficiary, balance);
        }

        // Destroy the option tokens before destroying the market itself.
        options.up.expire(beneficiary);
        options.down.expire(beneficiary);
        selfdestruct(beneficiary);
    }

    modifier duringMinting() {
        require(!_matured(), "Minting inactive");
        _;
    }

    modifier afterMaturity() {
        require(_matured(), "Not yet mature");
        _;
    }

    modifier managerNotPaused() {
        _requireManagerNotPaused();
        _;
    }

    /* ========== EVENTS ========== */

    event Mint(Side side, address indexed account, uint value);
    event MarketResolved(
        Side result,
        uint oraclePrice,
        uint oracleTimestamp,
        uint deposited,
        uint poolFees,
        uint creatorFees
    );

    event OptionsExercised(address indexed account, uint value);
    event OptionsBurned(address indexed account, uint value);
    event Expired(address beneficiary);
}

File 10 of 20 : Position.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

// Inheritance
import "@openzeppelin/contracts-4.4.1/token/ERC20/IERC20.sol";
import "../interfaces/IPosition.sol";

// Libraries
import "@openzeppelin/contracts-4.4.1/utils/math/SafeMath.sol";

// Internal references
import "./PositionalMarket.sol";

contract Position is IERC20, IPosition {
    using SafeMath for uint;

    string public name;
    string public symbol;
    uint8 public constant decimals = 18;

    PositionalMarket public market;

    mapping(address => uint) public override balanceOf;
    uint public override totalSupply;

    // The argument order is allowance[owner][spender]
    mapping(address => mapping(address => uint)) private allowances;

    // Enforce a 1 cent minimum amount
    uint internal constant _MINIMUM_AMOUNT = 1e16;

    address public thalesAMM;

    bool public initialized = false;

    function initialize(
        string calldata _name,
        string calldata _symbol,
        address _thalesAMM
    ) external {
        require(!initialized, "Positional Market already initialized");
        initialized = true;
        name = _name;
        symbol = _symbol;
        market = PositionalMarket(msg.sender);
        thalesAMM = _thalesAMM;
    }

    /// @notice allowance inherited IERC20 function
    /// @param owner address of the owner
    /// @param spender address of the spender
    /// @return uint256 number of tokens
    function allowance(address owner, address spender) external view override returns (uint256) {
        if (spender == thalesAMM) {
            return type(uint256).max;
        } else {
            return allowances[owner][spender];
        }
    }

    /// @notice mint function mints Position token
    /// @param minter address of the minter
    /// @param amount value to mint token for
    function mint(address minter, uint amount) external onlyMarket {
        _requireMinimumAmount(amount);
        totalSupply = totalSupply.add(amount);
        balanceOf[minter] = balanceOf[minter].add(amount); // Increment rather than assigning since a transfer may have occurred.

        emit Transfer(address(0), minter, amount);
        emit Issued(minter, amount);
    }

    /// @notice exercise function exercises Position token
    /// @dev This must only be invoked after maturity.
    /// @param claimant address of the claiming address
    function exercise(address claimant) external onlyMarket {
        uint balance = balanceOf[claimant];

        if (balance == 0) {
            return;
        }

        balanceOf[claimant] = 0;
        totalSupply = totalSupply.sub(balance);

        emit Transfer(claimant, address(0), balance);
        emit Burned(claimant, balance);
    }

    /// @notice exerciseWithAmount function exercises Position token
    /// @dev This must only be invoked after maturity.
    /// @param claimant address of the claiming address
    /// @param amount amount of tokens for exercising
    function exerciseWithAmount(address claimant, uint amount) external override onlyMarket {
        require(amount > 0, "Can not exercise zero amount!");

        require(balanceOf[claimant] >= amount, "Balance must be greather or equal amount that is burned");

        balanceOf[claimant] = balanceOf[claimant] - amount;
        totalSupply = totalSupply.sub(amount);

        emit Transfer(claimant, address(0), amount);
        emit Burned(claimant, amount);
    }

    /// @notice expire function is used for Position selfdestruct
    /// @dev This must only be invoked after the exercise window is complete.
    /// Any options which have not been exercised will linger.
    /// @param beneficiary address of the Position token
    function expire(address payable beneficiary) external onlyMarket {
        selfdestruct(beneficiary);
    }

    /// @notice transfer is ERC20 function for transfer tokens
    /// @param _to address of the receiver
    /// @param _value value to be transferred
    /// @return success
    function transfer(address _to, uint _value) external override returns (bool success) {
        return _transfer(msg.sender, _to, _value);
    }

    /// @notice transferFrom is ERC20 function for transfer tokens
    /// @param _from address of the sender
    /// @param _to address of the receiver
    /// @param _value value to be transferred
    /// @return success
    function transferFrom(
        address _from,
        address _to,
        uint _value
    ) external override returns (bool success) {
        if (msg.sender != thalesAMM) {
            uint fromAllowance = allowances[_from][msg.sender];
            require(_value <= fromAllowance, "Insufficient allowance");
            allowances[_from][msg.sender] = fromAllowance.sub(_value);
        }
        return _transfer(_from, _to, _value);
    }

    /// @notice approve is ERC20 function for token approval
    /// @param _spender address of the spender
    /// @param _value value to be approved
    /// @return success
    function approve(address _spender, uint _value) external override returns (bool success) {
        require(_spender != address(0));
        allowances[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }

    /// @notice getBalanceOf ERC20 function gets token balance of an account
    /// @param account address of the account
    /// @return uint
    function getBalanceOf(address account) external view override returns (uint) {
        return balanceOf[account];
    }

    /// @notice getTotalSupply ERC20 function gets token total supply
    /// @return uint
    function getTotalSupply() external view override returns (uint) {
        return totalSupply;
    }

    /// @notice transfer is internal function for transfer tokens
    /// @param _from address of the sender
    /// @param _to address of the receiver
    /// @param _value value to be transferred
    /// @return success
    function _transfer(
        address _from,
        address _to,
        uint _value
    ) internal returns (bool success) {
        market.requireUnpaused();
        require(_to != address(0) && _to != address(this), "Invalid address");

        uint fromBalance = balanceOf[_from];
        require(_value <= fromBalance, "Insufficient balance");

        balanceOf[_from] = fromBalance.sub(_value);
        balanceOf[_to] = balanceOf[_to].add(_value);

        emit Transfer(_from, _to, _value);
        return true;
    }

    /// @notice _requireMinimumAmount checks that amount is greater than minimum amount
    /// @param amount value to be checked
    /// @return uint amount
    function _requireMinimumAmount(uint amount) internal pure returns (uint) {
        require(amount >= _MINIMUM_AMOUNT || amount == 0, "Balance < $0.01");
        return amount;
    }

    modifier onlyMarket() {
        require(msg.sender == address(market), "Only market allowed");
        _;
    }

    event Issued(address indexed account, uint value);
    event Burned(address indexed account, uint value);
}

File 11 of 20 : 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 12 of 20 : 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 13 of 20 : IThalesAMM.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.16;

import "./IPriceFeed.sol";

interface IThalesAMM {
    enum Position {
        Up,
        Down
    }

    function manager() external view returns (address);

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

    function impliedVolatilityPerAsset(bytes32 oracleKey) external view returns (uint);

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

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

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

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

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

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

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

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

    function priceFeed() external view returns (IPriceFeed);
}

File 14 of 20 : 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 15 of 20 : 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 16 of 20 : 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 17 of 20 : 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 18 of 20 : OwnedWithInit.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract OwnedWithInit {
    address public owner;
    address public nominatedOwner;

    constructor() {}

    function initOwner(address _owner) internal {
        require(owner == address(0), "Init can only be called when owner is 0");
        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);
    }

    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 19 of 20 : IOracleInstance.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

interface IOracleInstance {
    /* ========== VIEWS / VARIABLES ========== */

    function getOutcome() external view returns (bool);

    function resolvable() external view returns (bool);
}

File 20 of 20 : 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);
            }
        }
    }
}

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

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"duration","type":"uint256"}],"name":"ExpiryDurationUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"market","type":"address"},{"indexed":true,"internalType":"address","name":"creator","type":"address"},{"indexed":true,"internalType":"bytes32","name":"oracleKey","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"strikePrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"maturityDate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"expiryDate","type":"uint256"},{"indexed":false,"internalType":"address","name":"up","type":"address"},{"indexed":false,"internalType":"address","name":"down","type":"address"},{"indexed":false,"internalType":"bool","name":"customMarket","type":"bool"},{"indexed":false,"internalType":"address","name":"customOracle","type":"address"}],"name":"MarketCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"enabled","type":"bool"}],"name":"MarketCreationEnabledUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_allowedDate1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_allowedDate2","type":"uint256"}],"name":"MarketCreationParametersChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"market","type":"address"}],"name":"MarketExpired","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract PositionalMarketManager","name":"receivingManager","type":"address"},{"indexed":false,"internalType":"contract PositionalMarket[]","name":"markets","type":"address[]"}],"name":"MarketsMigrated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract PositionalMarketManager","name":"migratingManager","type":"address"},{"indexed":false,"internalType":"contract PositionalMarket[]","name":"markets","type":"address[]"}],"name":"MarketsReceived","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"duration","type":"uint256"}],"name":"MaxTimeToMaturityUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerNominated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"isPaused","type":"bool"}],"name":"PauseChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"priceBuffer","type":"uint256"}],"name":"PriceBufferChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"manager","type":"address"}],"name":"SetMigratingManager","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"_SetOnlyAMMMintingAndBurning","type":"bool"}],"name":"SetOnlyAMMMintingAndBurning","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_positionalMarketFactory","type":"address"}],"name":"SetPositionalMarketFactory","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_address","type":"address"}],"name":"SetPriceFeed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_zeroExAddress","type":"address"}],"name":"SetZeroExAddress","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_address","type":"address"}],"name":"SetsUSD","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"timeframeBuffer","type":"uint256"}],"name":"TimeframeBufferChanged","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"uint256","name":"pageSize","type":"uint256"}],"name":"activeMarkets","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"addWhitelistedAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"allowedDate1","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allowedDate2","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"oracleKey","type":"bytes32"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"strikePrice","type":"uint256"}],"name":"canCreateMarket","outputs":[{"internalType":"bool","name":"","type":"bool"},{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"capitalRequirement","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"oracleKey","type":"bytes32"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"initialMint","type":"uint256"}],"name":"createMarket","outputs":[{"internalType":"contract IPositionalMarket","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"customMarketCreationEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"delta","type":"uint256"}],"name":"decrementTotalDeposited","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"disableWhitelistedAddresses","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"durations","outputs":[{"internalType":"uint256","name":"expiryDuration","type":"uint256"},{"internalType":"uint256","name":"maxTimeToMaturity","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"enableWhitelistedAddresses","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"markets","type":"address[]"}],"name":"expireMarkets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"oracleKey","type":"bytes32"}],"name":"getStrikePriceStep","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getThalesAMM","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"delta","type":"uint256"}],"name":"incrementTotalDeposited","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"contract IERC20","name":"_sUSD","type":"address"},{"internalType":"contract IPriceFeed","name":"_priceFeed","type":"address"},{"internalType":"uint256","name":"_expiryDuration","type":"uint256"},{"internalType":"uint256","name":"_maxTimeToMaturity","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"candidate","type":"address"}],"name":"isActiveMarket","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"candidate","type":"address"}],"name":"isKnownMarket","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastPauseTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"marketCreationEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"marketCreationMonthLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"marketExistsByOracleKeyDateAndStrikePrice","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"marketsPerOracleKey","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"marketsStrikePrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"uint256","name":"pageSize","type":"uint256"}],"name":"maturedMarkets","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"needsTransformingCollateral","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"nominateNewOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nominatedOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"numActiveMarkets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"numMaturedMarkets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"onlyAMMMintingAndBurning","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"onlyWhitelistedAddressesCanCreateMarkets","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionalMarketFactory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"priceBuffer","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"priceFeed","outputs":[{"internalType":"contract IPriceFeed","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"removeWhitelistedAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"}],"name":"resolveMarket","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"markets","type":"address[]"}],"name":"resolveMarketsBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"reverseTransformCollateral","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sUSD","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_expiryDuration","type":"uint256"}],"name":"setExpiryDuration","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"enabled","type":"bool"}],"name":"setMarketCreationEnabled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_allowedDate1","type":"uint256"},{"internalType":"uint256","name":"_allowedDate2","type":"uint256"}],"name":"setMarketCreationParameters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxTimeToMaturity","type":"uint256"}],"name":"setMaxTimeToMaturity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_needsTransformingCollateral","type":"bool"}],"name":"setNeedsTransformingCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_onlyAMMMintingAndBurning","type":"bool"}],"name":"setOnlyAMMMintingAndBurning","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_paused","type":"bool"}],"name":"setPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_positionalMarketFactory","type":"address"}],"name":"setPositionalMarketFactory","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_priceBuffer","type":"uint256"}],"name":"setPriceBuffer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"setPriceFeed","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_timeframeBuffer","type":"uint256"}],"name":"setTimeframeBuffer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_whitelistedAddresses","type":"address[]"}],"name":"setWhitelistedAddresses","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"setsUSD","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"timeframeBuffer","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalDeposited","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"proxyAddress","type":"address"}],"name":"transferOwnershipAtInit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferSusdTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transformCollateral","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelistedAddresses","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]

608060405234801561001057600080fd5b50612fa0806100206000396000f3fe608060405234801561001057600080fd5b50600436106103d05760003560e01c80638da5cb5b116101ff578063cf5a8e1e1161011a578063edc892e1116100ad578063f99ffbd01161007c578063f99ffbd01461086d578063fab44cbb14610876578063fcda2cdf14610889578063ff50abdc1461089657600080fd5b8063edc892e11461082b578063ee8f67701461083e578063f1528ae114610847578063f8d88a071461085a57600080fd5b8063e1e09d79116100e9578063e1e09d79146107d1578063e62b8889146107e4578063e73efc9b146107f7578063ed92acf21461080a57600080fd5b8063cf5a8e1e14610785578063d50f632314610798578063dd459f58146107ab578063dfa94a1b146107be57600080fd5b8063ab845b0811610192578063c014fb8411610161578063c014fb841461071c578063c0c293521461072f578063c3b83f5f14610738578063c84cc7c51461074b57600080fd5b8063ab845b08146106e6578063ac60c486146106ee578063aeab5849146106f6578063b908feb21461070957600080fd5b80639dc65440116101ce5780639dc65440146106a4578063a2132a59146106ad578063a6941b5a146106c0578063a6b63eb8146106d357600080fd5b80638da5cb5b1461065b5780638fe812b41461067457806391b4ded9146106885780639324cac71461069157600080fd5b80634a41d89d116102ef5780636b3a098411610282578063741bef1a11610251578063741bef1a1461060d5780637859f4101461062057806379ba50971461063357806389c6318d1461063b57600080fd5b80636b3a0984146105c15780636ec38a4e146105d4578063724e78da146105e75780637278227e146105fa57600080fd5b80635c975abb116102be5780635c975abb1461058c57806360518e4d1461059957806364af2d87146105a157806364cf34bd146105ae57600080fd5b80634a41d89d14610530578063530cd5ab1461055357806353a47bb71461056657806353c52f771461057957600080fd5b80631627540c1161036757806329975b431161033657806329975b43146104bf5780633495f3e3146104d257806339ab4c41146104f2578063415a9a151461050557600080fd5b80631627540c1461047d57806316c38b3c1461049057806317fd849a146104a35780631beb1eee146104b657600080fd5b80630d68cc46116103a35780630d68cc461461043d5780630e429aeb1461044557806313af403514610457578063155028401461046a57600080fd5b806302610c50146103d557806302b00358146103ec57806306c933d8146103f55780630b3be3f314610428575b600080fd5b600a545b6040519081526020015b60405180910390f35b6103d960135481565b61041861040336600461299b565b60086020526000908152604090205460ff1681565b60405190151581526020016103e3565b61043b61043636600461299b565b61089f565b005b61043b6108fc565b60075461041890610100900460ff1681565b61043b61046536600461299b565b610917565b61043b610478366004612b15565b610a50565b61043b61048b36600461299b565b610a8d565b61043b61049e366004612add565b610ae3565b6103d96104b1366004612b15565b610b59565b6103d960065481565b61043b6104cd36600461299b565b610b8c565b6103d96104e036600461299b565b60156020526000908152604090205481565b61043b610500366004612add565b610bb8565b610518610513366004612b58565b610c11565b6040516001600160a01b0390911681526020016103e3565b60045460055461053e919082565b604080519283526020830191909152016103e3565b61043b61056136600461299b565b61100e565b600154610518906001600160a01b031681565b61043b61058736600461299b565b611037565b6003546104189060ff1681565b61051861108d565b6007546104189060ff1681565b61043b6105bc366004612b15565b61110f565b61043b6105cf366004612b15565b61114c565b6104186105e236600461299b565b6111e1565b61043b6105f536600461299b565b6111ee565b6103d9610608366004612b15565b611244565b600f54610518906001600160a01b031681565b61043b61062e36600461299b565b6114c6565b61043b611586565b61064e610649366004612bda565b611683565b6040516103e39190612c46565b600054610518906201000090046001600160a01b031681565b60115461041890600160a01b900460ff1681565b6103d960025481565b601054610518906001600160a01b031681565b6103d960185481565b6105186106bb366004612b2d565b611698565b61043b6106ce366004612a6d565b6116dd565b61043b6106e1366004612a13565b6117bb565b61043b6118ee565b600c546103d9565b61043b610704366004612b15565b611904565b61043b6107173660046129d3565b611996565b61043b61072a366004612a6d565b611ac1565b6103d960195481565b61043b61074636600461299b565b611c33565b610518610759366004612b2d565b601a6020908152600093845260408085208252928452828420905282529020546001600160a01b031681565b601154610518906001600160a01b031681565b61043b6107a6366004612b15565b611d4c565b6007546104189062010000900460ff1681565b61043b6107cc366004612add565b611d89565b61043b6107df366004612b15565b611dd2565b6104186107f236600461299b565b611e0f565b61064e610805366004612bda565b611e2d565b61081d610818366004612b2d565b611e3b565b6040516103e3929190612c93565b6103d9610839366004612b15565b61214e565b6103d960175481565b61043b610855366004612a6d565b612159565b61043b610868366004612bda565b61224d565b6103d960125481565b61043b610884366004612add565b61229c565b6016546104189060ff1681565b6103d960095481565b6108a76122c2565b601080546001600160a01b0319166001600160a01b0383169081179091556040519081527fbae3da9b16d7b09b9f1a0d00cb2fafc0f94895fde1e0e2d9e31529efa028da06906020015b60405180910390a150565b6109046122c2565b6007805462ff0000191662010000179055565b6001600160a01b0381166109725760405162461bcd60e51b815260206004820152601960248201527f4f776e657220616464726573732063616e6e6f7420626520300000000000000060448201526064015b60405180910390fd5b600154600160a01b900460ff16156109de5760405162461bcd60e51b815260206004820152602960248201527f416c726561647920696e697469616c697a65642c20757365206e6f6d696e617460448201526832a732bba7bbb732b960b91b6064820152608401610969565b6001805460ff60a01b1916600160a01b179055600080546001600160a01b03831662010000810262010000600160b01b03199092169190911782556040805192835260208301919091527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c91016108f1565b610a586122c2565b60048190556040518181527ff378a0fd4ad3ffd9d7d50986f16b04acd2dc42691c4f412f34e8eefe883e6652906020016108f1565b610a956122c2565b600180546001600160a01b0319166001600160a01b0383169081179091556040519081527f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce22906020016108f1565b610aeb6122c2565b60035460ff1615158115151415610aff5750565b6003805460ff191682151590811790915560ff1615610b1d57426002555b60035460405160ff909116151581527f8fb6c181ee25a520cf3dd6565006ef91229fcfe5a989566c2a3b8c115570cec5906020016108f1565b50565b601154600090600160a01b900460ff1615610b8357610b7d8264e8d4a51000612eb6565b92915050565b5090565b919050565b610b946122c2565b6001600160a01b03166000908152600860205260409020805460ff19166001179055565b610bc06122c2565b60075460ff16151581151514610b56576007805460ff19168215159081179091556040519081527fcc590b6309435383b617aaa0cae6aba938f2ee471cfb539201dd7655a23caff9906020016108f1565b60035460009060ff1615610c375760405162461bcd60e51b815260040161096990612cc1565b60075462010000900460ff1615610cbd573360009081526008602052604090205460ff16610cbd5760405162461bcd60e51b815260206004820152602d60248201527f4f6e6c792077686974656c6973746564206164647265737365732063616e206360448201526c7265617465206d61726b65747360981b6064820152608401610969565b600080610ccb878688611e3b565b91509150818190610cef5760405162461bcd60e51b81526004016109699190612cae565b50600454600090610d0190879061233c565b6011546040805160e0810182523381526010546001600160a01b03908116602080840191909152600f54821683850152606083018e9052608083018d9052835180850185528c815290810186905260a083015260c082018a90529151634e627ee960e11b81529394506000939190921691639cc4fdd291610d859190600401612d1e565b602060405180830381600087803b158015610d9f57600080fd5b505af1158015610db3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dd791906129b7565b9050610de4600a82612348565b600954610df1908761233c565b6009556010546001600160a01b03166323b872dd3383610e108a61239b565b6040516001600160e01b031960e086901b1681526001600160a01b0393841660048201529290911660248301526044820152606401602060405180830381600087803b158015610e5f57600080fd5b505af1158015610e73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e979190612af9565b50600080826001600160a01b031663cc2ee1966040518163ffffffff1660e01b8152600401604080518083038186803b158015610ed357600080fd5b505afa158015610ee7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f0b9190612b89565b9150915082601a60008d815260200190815260200160002060008b815260200190815260200160002060008c815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055508a336001600160a01b03167f7f681fcb8e8dbe5d590262f6cbc95ff1f3106f3faae484a573b74f3de4b0ef96858d8d898888600080604051610ff79897969594939291906001600160a01b0398891681526020810197909752604087019590955260608601939093529085166080850152841660a0840152151560c083015290911660e08201526101000190565b60405180910390a350909998505050505050505050565b6110166122c2565b6001600160a01b03166000908152600860205260409020805460ff19169055565b61103f6122c2565b601180546001600160a01b0319166001600160a01b0383169081179091556040519081527f01ac44b8e741822cc089496ccd88fd432519fbf7c1cfc43aab7957522b08d309906020016108f1565b60115460408051632b971b7360e11b815290516000926001600160a01b03169163572e36e6916004808301926020929190829003018186803b1580156110d257600080fd5b505afa1580156110e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061110a91906129b7565b905090565b6111176122c2565b60058190556040518181527f6de18e808fc4e6cb9c8910cf4bdc188ddbbdab65faecff65dab871720e848489906020016108f1565b61115533611e0f565b6111ab5760405162461bcd60e51b815260206004820152602160248201527f5065726d6974746564206f6e6c7920666f72206b6e6f776e206d61726b6574736044820152601760f91b6064820152608401610969565b60035460ff16156111ce5760405162461bcd60e51b815260040161096990612cc1565b6009546111db90826123bf565b60095550565b6000610b7d600a836123cb565b6111f66122c2565b600f80546001600160a01b0319166001600160a01b0383169081179091556040519081527ff724a45d041687842411f2b977ef22ab8f43c8f1104f4592b42a00f9b34a643d906020016108f1565b600061124f8261244d565b61125b57506000919050565b6000611271670de0b6b3a76400006107d0612eb6565b61127a8461244d565b600f546040516315905ec160e31b8152600481018790526001600160a01b039091169063ac82f6089060240160206040518083038186803b1580156112be57600080fd5b505afa1580156112d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112f69190612bc2565b6113009190612eb6565b61130a9190612db7565b9050600061131782612551565b60408051606081018252600181526002602082015260039181019190915290915060006113458484806125cc565b905060005b60038110156114bc5761138483826003811061137657634e487b7160e01b600052603260045260246000fd5b602002015160ff168361261e565b955085851180156113a0575061139c60016003612ed5565b8114155b156113aa576114aa565b85851180156113c357506113c060016003612ed5565b81145b15611431576113f3856113d7866001612d9f565b86156113ed576113e8600188612ed5565b6125cc565b866125cc565b9150600061140b84825b602002015160ff168461261e565b90506114178682612ed5565b6114218888612ed5565b111561142b578096505b506114bc565b6000816114665761145286611447600188612ed5565b6113e8886001612d9f565b925061145f8460026113fd565b9050611496565b61149384611475600185612ed5565b600381106113fd57634e487b7160e01b600052603260045260246000fd5b90505b6114a08187612ed5565b6114218789612ed5565b806114b481612eec565b91505061134a565b5050505050919050565b6114d1600a826123cb565b6115145760405162461bcd60e51b8152602060048201526014602482015273139bdd08185b881858dd1a5d99481b585c9ad95d60621b6044820152606401610969565b806001600160a01b0316632810e1d66040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561154f57600080fd5b505af1158015611563573d6000803e3d6000fd5b5050505061157b81600a61264190919063ffffffff16565b610b56600c82612348565b6001546001600160a01b031633146115fe5760405162461bcd60e51b815260206004820152603560248201527f596f75206d757374206265206e6f6d696e61746564206265666f726520796f7560448201527402063616e20616363657074206f776e65727368697605c1b6064820152608401610969565b60005460015460408051620100009093046001600160a01b03908116845290911660208301527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c910160405180910390a1600180546000805462010000600160b01b0319166001600160a01b03831662010000021790556001600160a01b0319169055565b6060611691600c84846127c4565b9392505050565b601460205282600052604060002060205281600052604060002081815481106116c057600080fd5b6000918252602090912001546001600160a01b0316925083915050565b60005b818110156117b657600083838381811061170a57634e487b7160e01b600052603260045260246000fd5b905060200201602081019061171f919061299b565b905061172c600a826123cb565b156117a357806001600160a01b0316632810e1d66040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561176c57600080fd5b505af1158015611780573d6000803e3d6000fd5b5050505061179881600a61264190919063ffffffff16565b6117a3600c82612348565b50806117ae81612eec565b9150506116e0565b505050565b600054610100900460ff166117d65760005460ff16156117da565b303b155b61183d5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610969565b600054610100900460ff1615801561185f576000805461ffff19166101011790555b61186886610917565b600f80546001600160a01b038087166001600160a01b03199283161790925560108054928816929091169190911790556000805462010000330262010000600160b01b03199091161790556007805462ffffff191660011790556118cb83610a50565b6118d48261110f565b80156118e6576000805461ff00191690555b505050505050565b6118f66122c2565b6007805462ff000019169055565b61190f600a336123cb565b6119665760405162461bcd60e51b815260206004820152602260248201527f5065726d6974746564206f6e6c7920666f7220616374697665206d61726b6574604482015261399760f11b6064820152608401610969565b60035460ff16156119895760405162461bcd60e51b815260040161096990612cc1565b6009546111db908261233c565b61199f33611e0f565b6119dd5760405162461bcd60e51b815260206004820152600f60248201526e26b0b935b2ba103ab735b737bbb71760891b6044820152606401610969565b6010546040516323b872dd60e01b81526001600160a01b03858116600483015284811660248301526044820184905260009216906323b872dd90606401602060405180830381600087803b158015611a3457600080fd5b505af1158015611a48573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a6c9190612af9565b905080611abb5760405162461bcd60e51b815260206004820152601c60248201527f5472616e7366657246726f6d2066756e6374696f6e206661696c6564000000006044820152606401610969565b50505050565b60035460ff1615611ae45760405162461bcd60e51b815260040161096990612cc1565b611aec6122c2565b60005b818110156117b6576000838383818110611b1957634e487b7160e01b600052603260045260246000fd5b9050602002016020810190611b2e919061299b565b9050611b3981611e0f565b611b775760405162461bcd60e51b815260206004820152600f60248201526e26b0b935b2ba103ab735b737bbb71760891b6044820152606401610969565b60405163646d919f60e11b81523360048201526001600160a01b0382169063c8db233e90602401600060405180830381600087803b158015611bb857600080fd5b505af1158015611bcc573d6000803e3d6000fd5b50505050611be481600c61264190919063ffffffff16565b6040516001600160a01b03821681527f16e62064e42f5aec62df22ae895ef539f153e0d4ea290e2cc4e0e8f708f2fbbc9060200160405180910390a15080611c2b81612eec565b915050611aef565b611c3b6122c2565b6001600160a01b038116611c835760405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b6044820152606401610969565b600154600160a81b900460ff1615611cd35760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481d1c985b9cd9995c9c9959606a1b6044820152606401610969565b600080546001600160a01b038381166201000081810262010000600160b01b031990941693909317938490556001805460ff60a81b1916600160a81b1790556040805193909404909116825260208201527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c91016108f1565b611d546122c2565b60128190556040518181527ffbdb0650d5ceb863facfa4e3f99be3d09a55a0340bdcca439c1265b04a80f07d906020016108f1565b611d916122c2565b6016805460ff19168215159081179091556040519081527f076d83e2edbcbadf01c08340a7fa2f1a60009185deb77d604c64a547ab5373a0906020016108f1565b611dda6122c2565b60138190556040518181527f7b50cbf47ca582d357769ef0373078636c9621961c0c139a414989eb321b9da8906020016108f1565b6000611e1c600a836123cb565b80610b7d5750610b7d600c836123cb565b6060611691600a84846127c4565b60075460009060609060ff16611e8957505060408051808201909152601b81527f4d61726b6574206372656174696f6e2069732064697361626c656400000000006020820152600090612146565b611e9285612909565b611ec257505060408051808201909152600b81526a496e76616c6964206b657960a81b6020820152600090612146565b600554611ecf9042612d9f565b841115611f1457505060408051808201909152601e81527f4d6174757269747920746f6f2066617220696e207468652066757475726500006020820152600090612146565b834210611f5957505060408051808201909152601e81527f4d617475726974792063616e6e6f7420626520696e20746865207061737400006020820152600090612146565b6000858152601a6020908152604080832087845282528083208684529091529020546001600160a01b031615611fbf5750506040805180820190915260158152744d61726b657420616c72656164792065786973747360581b6020820152600090612146565b6000611fca86611244565b600f546040516315905ec160e31b8152600481018990529192506000916001600160a01b039091169063ac82f6089060240160206040518083038186803b15801561201457600080fd5b505afa158015612028573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061204c9190612bc2565b9050811580159061206557506120628286612f07565b15155b156120a457600060405180604001604052806014815260200173496e76616c696420737472696b6520707269636560601b815250935093505050612146565b600062093a80601854886120b89190612ed5565b6120c29190612f07565b9050600062093a80601954896120d89190612ed5565b6120e29190612f07565b90508115806120ef575080155b61212b5760006040518060400160405280601081526020016f496e76616c6964206d6174757269747960801b8152509550955050505050612146565b60016040518060200160405280600081525095509550505050505b935093915050565b6000610b7d8261239b565b6121616122c2565b806121bc5760405162461bcd60e51b815260206004820152602560248201527f57686974656c6973746564206164647265737365732063616e6e6f7420626520604482015264656d70747960d81b6064820152608401610969565b6007805462ff000019166201000017905560005b818110156117b6576001600860008585858181106121fe57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190612213919061299b565b6001600160a01b031681526020810191909152604001600020805460ff19169115159190911790558061224581612eec565b9150506121d0565b6122556122c2565b6018829055601981905560408051838152602081018390527f673e07effe3d14605e5e63d37d96ee1116178092c80ac08bffe85ba2e3a9617f910160405180910390a15050565b6122a46122c2565b60118054911515600160a01b0260ff60a01b19909216919091179055565b6000546201000090046001600160a01b0316331461233a5760405162461bcd60e51b815260206004820152602f60248201527f4f6e6c792074686520636f6e7472616374206f776e6572206d6179207065726660448201526e37b936903a3434b99030b1ba34b7b760891b6064820152608401610969565b565b60006116918284612d9f565b61235282826123cb565b6123975781546001600160a01b038216600081815260018086016020908152604083208590559084018655858252902090910180546001600160a01b03191690911790555b5050565b601154600090600160a01b900460ff1615610b8357610b7d64e8d4a5100083612db7565b60006116918284612ed5565b81546000906123dc57506000610b7d565b6001600160a01b0382166000908152600184016020526040902054801515806124455750826001600160a01b03168460000160008154811061242e57634e487b7160e01b600052603260045260246000fd5b6000918252602090912001546001600160a01b0316145b949350505050565b600080601160009054906101000a90046001600160a01b03166001600160a01b031663572e36e66040518163ffffffff1660e01b815260040160206040518083038186803b15801561249e57600080fd5b505afa1580156124b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124d691906129b7565b60405163f502b00360e01b8152600481018590529091506001600160a01b0382169063f502b0039060240160206040518083038186803b15801561251957600080fd5b505afa15801561252d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116919190612bc2565b6000670de0b6b3a7640000821061259d575b670de0b6b3a76400008211156125925761257e600a83612db7565b915061258b600182612d9f565b9050612563565b610b7d600182612ed5565b670de0b6b3a7640000821015610b87576125b8600a83612eb6565b91506125c5600182612d9f565b905061259d565b6000670de0b6b3a7640000841015612600576125e982600a612e0e565b6125fb90670de0b6b3a7640000612db7565b612445565b670de0b6b3a764000061261484600a612e0e565b6124459190612eb6565b6000818361262d816002612e0e565b6126379190612ed5565b6116919190612eb6565b61264b82826123cb565b61268d5760405162461bcd60e51b815260206004820152601360248201527222b632b6b2b73a103737ba1034b71039b2ba1760691b6044820152606401610969565b6001600160a01b03811660009081526001808401602052604082205484549092916126b791612ed5565b905080821461275f5760008460000182815481106126e557634e487b7160e01b600052603260045260246000fd5b60009182526020909120015485546001600160a01b039091169150819086908590811061272257634e487b7160e01b600052603260045260246000fd5b600091825260208083209190910180546001600160a01b0319166001600160a01b0394851617905592909116815260018601909152604090208290555b835484908061277e57634e487b7160e01b600052603160045260246000fd5b60008281526020808220830160001990810180546001600160a01b03191690559092019092556001600160a01b0394909416815260019490940190925250506040812055565b606060006127d28385612d9f565b85549091508111156127e2575083545b8381116127ff575050604080516000815260208101909152611691565b600061280b8583612ed5565b905060008167ffffffffffffffff81111561283657634e487b7160e01b600052604160045260246000fd5b60405190808252806020026020018201604052801561285f578160200160208202803683370190505b50905060005b828110156128fe57876128788883612d9f565b8154811061289657634e487b7160e01b600052603260045260246000fd5b9060005260206000200160009054906101000a90046001600160a01b03168282815181106128d457634e487b7160e01b600052603260045260246000fd5b6001600160a01b0390921660209283029190910190910152806128f681612eec565b915050612865565b509695505050505050565b600f546040516315905ec160e31b8152600481018390526000916001600160a01b03169063ac82f6089060240160206040518083038186803b15801561294e57600080fd5b505afa158015612962573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129869190612bc2565b1561299357506001919050565b506000919050565b6000602082840312156129ac578081fd5b813561169181612f47565b6000602082840312156129c8578081fd5b815161169181612f47565b6000806000606084860312156129e7578182fd5b83356129f281612f47565b92506020840135612a0281612f47565b929592945050506040919091013590565b600080600080600060a08688031215612a2a578081fd5b8535612a3581612f47565b94506020860135612a4581612f47565b93506040860135612a5581612f47565b94979396509394606081013594506080013592915050565b60008060208385031215612a7f578182fd5b823567ffffffffffffffff80821115612a96578384fd5b818501915085601f830112612aa9578384fd5b813581811115612ab7578485fd5b8660208260051b8501011115612acb578485fd5b60209290920196919550909350505050565b600060208284031215612aee578081fd5b813561169181612f5c565b600060208284031215612b0a578081fd5b815161169181612f5c565b600060208284031215612b26578081fd5b5035919050565b600080600060608486031215612b41578283fd5b505081359360208301359350604090920135919050565b60008060008060808587031215612b6d578384fd5b5050823594602084013594506040840135936060013592509050565b60008060408385031215612b9b578182fd5b8251612ba681612f47565b6020840151909250612bb781612f47565b809150509250929050565b600060208284031215612bd3578081fd5b5051919050565b60008060408385031215612bec578182fd5b50508035926020909101359150565b60008151808452815b81811015612c2057602081850181015186830182015201612c04565b81811115612c315782602083870101525b50601f01601f19169290920160200192915050565b6020808252825182820181905260009190848201906040850190845b81811015612c875783516001600160a01b031683529284019291840191600101612c62565b50909695505050505050565b82151581526040602082015260006124456040830184612bfb565b6020815260006116916020830184612bfb565b6020808252603c908201527f5468697320616374696f6e2063616e6e6f7420626520706572666f726d65642060408201527f7768696c652074686520636f6e74726163742069732070617573656400000000606082015260800190565b60006101008201905060018060a01b03808451168352602081818601511681850152816040860151166040850152606085015160608501526080850151608085015260a0850151915060a0840160005b6002811015612d8b57835182529282019290820190600101612d6e565b5050505060c083015160e083015292915050565b60008219821115612db257612db2612f1b565b500190565b600082612dc657612dc6612f31565b500490565b600181815b80851115612e06578160001904821115612dec57612dec612f1b565b80851615612df957918102915b93841c9390800290612dd0565b509250929050565b60006116918383600082612e2457506001610b7d565b81612e3157506000610b7d565b8160018114612e475760028114612e5157612e6d565b6001915050610b7d565b60ff841115612e6257612e62612f1b565b50506001821b610b7d565b5060208310610133831016604e8410600b8410161715612e90575081810a610b7d565b612e9a8383612dcb565b8060001904821115612eae57612eae612f1b565b029392505050565b6000816000190483118215151615612ed057612ed0612f1b565b500290565b600082821015612ee757612ee7612f1b565b500390565b6000600019821415612f0057612f00612f1b565b5060010190565b600082612f1657612f16612f31565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b6001600160a01b0381168114610b5657600080fd5b8015158114610b5657600080fdfea2646970667358221220095345f0a2f72fbca41f7b83f86109c1ce9fe318c207daf8e98db29f2c86fc2864736f6c63430008040033

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106103d05760003560e01c80638da5cb5b116101ff578063cf5a8e1e1161011a578063edc892e1116100ad578063f99ffbd01161007c578063f99ffbd01461086d578063fab44cbb14610876578063fcda2cdf14610889578063ff50abdc1461089657600080fd5b8063edc892e11461082b578063ee8f67701461083e578063f1528ae114610847578063f8d88a071461085a57600080fd5b8063e1e09d79116100e9578063e1e09d79146107d1578063e62b8889146107e4578063e73efc9b146107f7578063ed92acf21461080a57600080fd5b8063cf5a8e1e14610785578063d50f632314610798578063dd459f58146107ab578063dfa94a1b146107be57600080fd5b8063ab845b0811610192578063c014fb8411610161578063c014fb841461071c578063c0c293521461072f578063c3b83f5f14610738578063c84cc7c51461074b57600080fd5b8063ab845b08146106e6578063ac60c486146106ee578063aeab5849146106f6578063b908feb21461070957600080fd5b80639dc65440116101ce5780639dc65440146106a4578063a2132a59146106ad578063a6941b5a146106c0578063a6b63eb8146106d357600080fd5b80638da5cb5b1461065b5780638fe812b41461067457806391b4ded9146106885780639324cac71461069157600080fd5b80634a41d89d116102ef5780636b3a098411610282578063741bef1a11610251578063741bef1a1461060d5780637859f4101461062057806379ba50971461063357806389c6318d1461063b57600080fd5b80636b3a0984146105c15780636ec38a4e146105d4578063724e78da146105e75780637278227e146105fa57600080fd5b80635c975abb116102be5780635c975abb1461058c57806360518e4d1461059957806364af2d87146105a157806364cf34bd146105ae57600080fd5b80634a41d89d14610530578063530cd5ab1461055357806353a47bb71461056657806353c52f771461057957600080fd5b80631627540c1161036757806329975b431161033657806329975b43146104bf5780633495f3e3146104d257806339ab4c41146104f2578063415a9a151461050557600080fd5b80631627540c1461047d57806316c38b3c1461049057806317fd849a146104a35780631beb1eee146104b657600080fd5b80630d68cc46116103a35780630d68cc461461043d5780630e429aeb1461044557806313af403514610457578063155028401461046a57600080fd5b806302610c50146103d557806302b00358146103ec57806306c933d8146103f55780630b3be3f314610428575b600080fd5b600a545b6040519081526020015b60405180910390f35b6103d960135481565b61041861040336600461299b565b60086020526000908152604090205460ff1681565b60405190151581526020016103e3565b61043b61043636600461299b565b61089f565b005b61043b6108fc565b60075461041890610100900460ff1681565b61043b61046536600461299b565b610917565b61043b610478366004612b15565b610a50565b61043b61048b36600461299b565b610a8d565b61043b61049e366004612add565b610ae3565b6103d96104b1366004612b15565b610b59565b6103d960065481565b61043b6104cd36600461299b565b610b8c565b6103d96104e036600461299b565b60156020526000908152604090205481565b61043b610500366004612add565b610bb8565b610518610513366004612b58565b610c11565b6040516001600160a01b0390911681526020016103e3565b60045460055461053e919082565b604080519283526020830191909152016103e3565b61043b61056136600461299b565b61100e565b600154610518906001600160a01b031681565b61043b61058736600461299b565b611037565b6003546104189060ff1681565b61051861108d565b6007546104189060ff1681565b61043b6105bc366004612b15565b61110f565b61043b6105cf366004612b15565b61114c565b6104186105e236600461299b565b6111e1565b61043b6105f536600461299b565b6111ee565b6103d9610608366004612b15565b611244565b600f54610518906001600160a01b031681565b61043b61062e36600461299b565b6114c6565b61043b611586565b61064e610649366004612bda565b611683565b6040516103e39190612c46565b600054610518906201000090046001600160a01b031681565b60115461041890600160a01b900460ff1681565b6103d960025481565b601054610518906001600160a01b031681565b6103d960185481565b6105186106bb366004612b2d565b611698565b61043b6106ce366004612a6d565b6116dd565b61043b6106e1366004612a13565b6117bb565b61043b6118ee565b600c546103d9565b61043b610704366004612b15565b611904565b61043b6107173660046129d3565b611996565b61043b61072a366004612a6d565b611ac1565b6103d960195481565b61043b61074636600461299b565b611c33565b610518610759366004612b2d565b601a6020908152600093845260408085208252928452828420905282529020546001600160a01b031681565b601154610518906001600160a01b031681565b61043b6107a6366004612b15565b611d4c565b6007546104189062010000900460ff1681565b61043b6107cc366004612add565b611d89565b61043b6107df366004612b15565b611dd2565b6104186107f236600461299b565b611e0f565b61064e610805366004612bda565b611e2d565b61081d610818366004612b2d565b611e3b565b6040516103e3929190612c93565b6103d9610839366004612b15565b61214e565b6103d960175481565b61043b610855366004612a6d565b612159565b61043b610868366004612bda565b61224d565b6103d960125481565b61043b610884366004612add565b61229c565b6016546104189060ff1681565b6103d960095481565b6108a76122c2565b601080546001600160a01b0319166001600160a01b0383169081179091556040519081527fbae3da9b16d7b09b9f1a0d00cb2fafc0f94895fde1e0e2d9e31529efa028da06906020015b60405180910390a150565b6109046122c2565b6007805462ff0000191662010000179055565b6001600160a01b0381166109725760405162461bcd60e51b815260206004820152601960248201527f4f776e657220616464726573732063616e6e6f7420626520300000000000000060448201526064015b60405180910390fd5b600154600160a01b900460ff16156109de5760405162461bcd60e51b815260206004820152602960248201527f416c726561647920696e697469616c697a65642c20757365206e6f6d696e617460448201526832a732bba7bbb732b960b91b6064820152608401610969565b6001805460ff60a01b1916600160a01b179055600080546001600160a01b03831662010000810262010000600160b01b03199092169190911782556040805192835260208301919091527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c91016108f1565b610a586122c2565b60048190556040518181527ff378a0fd4ad3ffd9d7d50986f16b04acd2dc42691c4f412f34e8eefe883e6652906020016108f1565b610a956122c2565b600180546001600160a01b0319166001600160a01b0383169081179091556040519081527f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce22906020016108f1565b610aeb6122c2565b60035460ff1615158115151415610aff5750565b6003805460ff191682151590811790915560ff1615610b1d57426002555b60035460405160ff909116151581527f8fb6c181ee25a520cf3dd6565006ef91229fcfe5a989566c2a3b8c115570cec5906020016108f1565b50565b601154600090600160a01b900460ff1615610b8357610b7d8264e8d4a51000612eb6565b92915050565b5090565b919050565b610b946122c2565b6001600160a01b03166000908152600860205260409020805460ff19166001179055565b610bc06122c2565b60075460ff16151581151514610b56576007805460ff19168215159081179091556040519081527fcc590b6309435383b617aaa0cae6aba938f2ee471cfb539201dd7655a23caff9906020016108f1565b60035460009060ff1615610c375760405162461bcd60e51b815260040161096990612cc1565b60075462010000900460ff1615610cbd573360009081526008602052604090205460ff16610cbd5760405162461bcd60e51b815260206004820152602d60248201527f4f6e6c792077686974656c6973746564206164647265737365732063616e206360448201526c7265617465206d61726b65747360981b6064820152608401610969565b600080610ccb878688611e3b565b91509150818190610cef5760405162461bcd60e51b81526004016109699190612cae565b50600454600090610d0190879061233c565b6011546040805160e0810182523381526010546001600160a01b03908116602080840191909152600f54821683850152606083018e9052608083018d9052835180850185528c815290810186905260a083015260c082018a90529151634e627ee960e11b81529394506000939190921691639cc4fdd291610d859190600401612d1e565b602060405180830381600087803b158015610d9f57600080fd5b505af1158015610db3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dd791906129b7565b9050610de4600a82612348565b600954610df1908761233c565b6009556010546001600160a01b03166323b872dd3383610e108a61239b565b6040516001600160e01b031960e086901b1681526001600160a01b0393841660048201529290911660248301526044820152606401602060405180830381600087803b158015610e5f57600080fd5b505af1158015610e73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e979190612af9565b50600080826001600160a01b031663cc2ee1966040518163ffffffff1660e01b8152600401604080518083038186803b158015610ed357600080fd5b505afa158015610ee7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f0b9190612b89565b9150915082601a60008d815260200190815260200160002060008b815260200190815260200160002060008c815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055508a336001600160a01b03167f7f681fcb8e8dbe5d590262f6cbc95ff1f3106f3faae484a573b74f3de4b0ef96858d8d898888600080604051610ff79897969594939291906001600160a01b0398891681526020810197909752604087019590955260608601939093529085166080850152841660a0840152151560c083015290911660e08201526101000190565b60405180910390a350909998505050505050505050565b6110166122c2565b6001600160a01b03166000908152600860205260409020805460ff19169055565b61103f6122c2565b601180546001600160a01b0319166001600160a01b0383169081179091556040519081527f01ac44b8e741822cc089496ccd88fd432519fbf7c1cfc43aab7957522b08d309906020016108f1565b60115460408051632b971b7360e11b815290516000926001600160a01b03169163572e36e6916004808301926020929190829003018186803b1580156110d257600080fd5b505afa1580156110e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061110a91906129b7565b905090565b6111176122c2565b60058190556040518181527f6de18e808fc4e6cb9c8910cf4bdc188ddbbdab65faecff65dab871720e848489906020016108f1565b61115533611e0f565b6111ab5760405162461bcd60e51b815260206004820152602160248201527f5065726d6974746564206f6e6c7920666f72206b6e6f776e206d61726b6574736044820152601760f91b6064820152608401610969565b60035460ff16156111ce5760405162461bcd60e51b815260040161096990612cc1565b6009546111db90826123bf565b60095550565b6000610b7d600a836123cb565b6111f66122c2565b600f80546001600160a01b0319166001600160a01b0383169081179091556040519081527ff724a45d041687842411f2b977ef22ab8f43c8f1104f4592b42a00f9b34a643d906020016108f1565b600061124f8261244d565b61125b57506000919050565b6000611271670de0b6b3a76400006107d0612eb6565b61127a8461244d565b600f546040516315905ec160e31b8152600481018790526001600160a01b039091169063ac82f6089060240160206040518083038186803b1580156112be57600080fd5b505afa1580156112d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112f69190612bc2565b6113009190612eb6565b61130a9190612db7565b9050600061131782612551565b60408051606081018252600181526002602082015260039181019190915290915060006113458484806125cc565b905060005b60038110156114bc5761138483826003811061137657634e487b7160e01b600052603260045260246000fd5b602002015160ff168361261e565b955085851180156113a0575061139c60016003612ed5565b8114155b156113aa576114aa565b85851180156113c357506113c060016003612ed5565b81145b15611431576113f3856113d7866001612d9f565b86156113ed576113e8600188612ed5565b6125cc565b866125cc565b9150600061140b84825b602002015160ff168461261e565b90506114178682612ed5565b6114218888612ed5565b111561142b578096505b506114bc565b6000816114665761145286611447600188612ed5565b6113e8886001612d9f565b925061145f8460026113fd565b9050611496565b61149384611475600185612ed5565b600381106113fd57634e487b7160e01b600052603260045260246000fd5b90505b6114a08187612ed5565b6114218789612ed5565b806114b481612eec565b91505061134a565b5050505050919050565b6114d1600a826123cb565b6115145760405162461bcd60e51b8152602060048201526014602482015273139bdd08185b881858dd1a5d99481b585c9ad95d60621b6044820152606401610969565b806001600160a01b0316632810e1d66040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561154f57600080fd5b505af1158015611563573d6000803e3d6000fd5b5050505061157b81600a61264190919063ffffffff16565b610b56600c82612348565b6001546001600160a01b031633146115fe5760405162461bcd60e51b815260206004820152603560248201527f596f75206d757374206265206e6f6d696e61746564206265666f726520796f7560448201527402063616e20616363657074206f776e65727368697605c1b6064820152608401610969565b60005460015460408051620100009093046001600160a01b03908116845290911660208301527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c910160405180910390a1600180546000805462010000600160b01b0319166001600160a01b03831662010000021790556001600160a01b0319169055565b6060611691600c84846127c4565b9392505050565b601460205282600052604060002060205281600052604060002081815481106116c057600080fd5b6000918252602090912001546001600160a01b0316925083915050565b60005b818110156117b657600083838381811061170a57634e487b7160e01b600052603260045260246000fd5b905060200201602081019061171f919061299b565b905061172c600a826123cb565b156117a357806001600160a01b0316632810e1d66040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561176c57600080fd5b505af1158015611780573d6000803e3d6000fd5b5050505061179881600a61264190919063ffffffff16565b6117a3600c82612348565b50806117ae81612eec565b9150506116e0565b505050565b600054610100900460ff166117d65760005460ff16156117da565b303b155b61183d5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610969565b600054610100900460ff1615801561185f576000805461ffff19166101011790555b61186886610917565b600f80546001600160a01b038087166001600160a01b03199283161790925560108054928816929091169190911790556000805462010000330262010000600160b01b03199091161790556007805462ffffff191660011790556118cb83610a50565b6118d48261110f565b80156118e6576000805461ff00191690555b505050505050565b6118f66122c2565b6007805462ff000019169055565b61190f600a336123cb565b6119665760405162461bcd60e51b815260206004820152602260248201527f5065726d6974746564206f6e6c7920666f7220616374697665206d61726b6574604482015261399760f11b6064820152608401610969565b60035460ff16156119895760405162461bcd60e51b815260040161096990612cc1565b6009546111db908261233c565b61199f33611e0f565b6119dd5760405162461bcd60e51b815260206004820152600f60248201526e26b0b935b2ba103ab735b737bbb71760891b6044820152606401610969565b6010546040516323b872dd60e01b81526001600160a01b03858116600483015284811660248301526044820184905260009216906323b872dd90606401602060405180830381600087803b158015611a3457600080fd5b505af1158015611a48573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a6c9190612af9565b905080611abb5760405162461bcd60e51b815260206004820152601c60248201527f5472616e7366657246726f6d2066756e6374696f6e206661696c6564000000006044820152606401610969565b50505050565b60035460ff1615611ae45760405162461bcd60e51b815260040161096990612cc1565b611aec6122c2565b60005b818110156117b6576000838383818110611b1957634e487b7160e01b600052603260045260246000fd5b9050602002016020810190611b2e919061299b565b9050611b3981611e0f565b611b775760405162461bcd60e51b815260206004820152600f60248201526e26b0b935b2ba103ab735b737bbb71760891b6044820152606401610969565b60405163646d919f60e11b81523360048201526001600160a01b0382169063c8db233e90602401600060405180830381600087803b158015611bb857600080fd5b505af1158015611bcc573d6000803e3d6000fd5b50505050611be481600c61264190919063ffffffff16565b6040516001600160a01b03821681527f16e62064e42f5aec62df22ae895ef539f153e0d4ea290e2cc4e0e8f708f2fbbc9060200160405180910390a15080611c2b81612eec565b915050611aef565b611c3b6122c2565b6001600160a01b038116611c835760405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b6044820152606401610969565b600154600160a81b900460ff1615611cd35760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481d1c985b9cd9995c9c9959606a1b6044820152606401610969565b600080546001600160a01b038381166201000081810262010000600160b01b031990941693909317938490556001805460ff60a81b1916600160a81b1790556040805193909404909116825260208201527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c91016108f1565b611d546122c2565b60128190556040518181527ffbdb0650d5ceb863facfa4e3f99be3d09a55a0340bdcca439c1265b04a80f07d906020016108f1565b611d916122c2565b6016805460ff19168215159081179091556040519081527f076d83e2edbcbadf01c08340a7fa2f1a60009185deb77d604c64a547ab5373a0906020016108f1565b611dda6122c2565b60138190556040518181527f7b50cbf47ca582d357769ef0373078636c9621961c0c139a414989eb321b9da8906020016108f1565b6000611e1c600a836123cb565b80610b7d5750610b7d600c836123cb565b6060611691600a84846127c4565b60075460009060609060ff16611e8957505060408051808201909152601b81527f4d61726b6574206372656174696f6e2069732064697361626c656400000000006020820152600090612146565b611e9285612909565b611ec257505060408051808201909152600b81526a496e76616c6964206b657960a81b6020820152600090612146565b600554611ecf9042612d9f565b841115611f1457505060408051808201909152601e81527f4d6174757269747920746f6f2066617220696e207468652066757475726500006020820152600090612146565b834210611f5957505060408051808201909152601e81527f4d617475726974792063616e6e6f7420626520696e20746865207061737400006020820152600090612146565b6000858152601a6020908152604080832087845282528083208684529091529020546001600160a01b031615611fbf5750506040805180820190915260158152744d61726b657420616c72656164792065786973747360581b6020820152600090612146565b6000611fca86611244565b600f546040516315905ec160e31b8152600481018990529192506000916001600160a01b039091169063ac82f6089060240160206040518083038186803b15801561201457600080fd5b505afa158015612028573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061204c9190612bc2565b9050811580159061206557506120628286612f07565b15155b156120a457600060405180604001604052806014815260200173496e76616c696420737472696b6520707269636560601b815250935093505050612146565b600062093a80601854886120b89190612ed5565b6120c29190612f07565b9050600062093a80601954896120d89190612ed5565b6120e29190612f07565b90508115806120ef575080155b61212b5760006040518060400160405280601081526020016f496e76616c6964206d6174757269747960801b8152509550955050505050612146565b60016040518060200160405280600081525095509550505050505b935093915050565b6000610b7d8261239b565b6121616122c2565b806121bc5760405162461bcd60e51b815260206004820152602560248201527f57686974656c6973746564206164647265737365732063616e6e6f7420626520604482015264656d70747960d81b6064820152608401610969565b6007805462ff000019166201000017905560005b818110156117b6576001600860008585858181106121fe57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190612213919061299b565b6001600160a01b031681526020810191909152604001600020805460ff19169115159190911790558061224581612eec565b9150506121d0565b6122556122c2565b6018829055601981905560408051838152602081018390527f673e07effe3d14605e5e63d37d96ee1116178092c80ac08bffe85ba2e3a9617f910160405180910390a15050565b6122a46122c2565b60118054911515600160a01b0260ff60a01b19909216919091179055565b6000546201000090046001600160a01b0316331461233a5760405162461bcd60e51b815260206004820152602f60248201527f4f6e6c792074686520636f6e7472616374206f776e6572206d6179207065726660448201526e37b936903a3434b99030b1ba34b7b760891b6064820152608401610969565b565b60006116918284612d9f565b61235282826123cb565b6123975781546001600160a01b038216600081815260018086016020908152604083208590559084018655858252902090910180546001600160a01b03191690911790555b5050565b601154600090600160a01b900460ff1615610b8357610b7d64e8d4a5100083612db7565b60006116918284612ed5565b81546000906123dc57506000610b7d565b6001600160a01b0382166000908152600184016020526040902054801515806124455750826001600160a01b03168460000160008154811061242e57634e487b7160e01b600052603260045260246000fd5b6000918252602090912001546001600160a01b0316145b949350505050565b600080601160009054906101000a90046001600160a01b03166001600160a01b031663572e36e66040518163ffffffff1660e01b815260040160206040518083038186803b15801561249e57600080fd5b505afa1580156124b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124d691906129b7565b60405163f502b00360e01b8152600481018590529091506001600160a01b0382169063f502b0039060240160206040518083038186803b15801561251957600080fd5b505afa15801561252d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116919190612bc2565b6000670de0b6b3a7640000821061259d575b670de0b6b3a76400008211156125925761257e600a83612db7565b915061258b600182612d9f565b9050612563565b610b7d600182612ed5565b670de0b6b3a7640000821015610b87576125b8600a83612eb6565b91506125c5600182612d9f565b905061259d565b6000670de0b6b3a7640000841015612600576125e982600a612e0e565b6125fb90670de0b6b3a7640000612db7565b612445565b670de0b6b3a764000061261484600a612e0e565b6124459190612eb6565b6000818361262d816002612e0e565b6126379190612ed5565b6116919190612eb6565b61264b82826123cb565b61268d5760405162461bcd60e51b815260206004820152601360248201527222b632b6b2b73a103737ba1034b71039b2ba1760691b6044820152606401610969565b6001600160a01b03811660009081526001808401602052604082205484549092916126b791612ed5565b905080821461275f5760008460000182815481106126e557634e487b7160e01b600052603260045260246000fd5b60009182526020909120015485546001600160a01b039091169150819086908590811061272257634e487b7160e01b600052603260045260246000fd5b600091825260208083209190910180546001600160a01b0319166001600160a01b0394851617905592909116815260018601909152604090208290555b835484908061277e57634e487b7160e01b600052603160045260246000fd5b60008281526020808220830160001990810180546001600160a01b03191690559092019092556001600160a01b0394909416815260019490940190925250506040812055565b606060006127d28385612d9f565b85549091508111156127e2575083545b8381116127ff575050604080516000815260208101909152611691565b600061280b8583612ed5565b905060008167ffffffffffffffff81111561283657634e487b7160e01b600052604160045260246000fd5b60405190808252806020026020018201604052801561285f578160200160208202803683370190505b50905060005b828110156128fe57876128788883612d9f565b8154811061289657634e487b7160e01b600052603260045260246000fd5b9060005260206000200160009054906101000a90046001600160a01b03168282815181106128d457634e487b7160e01b600052603260045260246000fd5b6001600160a01b0390921660209283029190910190910152806128f681612eec565b915050612865565b509695505050505050565b600f546040516315905ec160e31b8152600481018390526000916001600160a01b03169063ac82f6089060240160206040518083038186803b15801561294e57600080fd5b505afa158015612962573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129869190612bc2565b1561299357506001919050565b506000919050565b6000602082840312156129ac578081fd5b813561169181612f47565b6000602082840312156129c8578081fd5b815161169181612f47565b6000806000606084860312156129e7578182fd5b83356129f281612f47565b92506020840135612a0281612f47565b929592945050506040919091013590565b600080600080600060a08688031215612a2a578081fd5b8535612a3581612f47565b94506020860135612a4581612f47565b93506040860135612a5581612f47565b94979396509394606081013594506080013592915050565b60008060208385031215612a7f578182fd5b823567ffffffffffffffff80821115612a96578384fd5b818501915085601f830112612aa9578384fd5b813581811115612ab7578485fd5b8660208260051b8501011115612acb578485fd5b60209290920196919550909350505050565b600060208284031215612aee578081fd5b813561169181612f5c565b600060208284031215612b0a578081fd5b815161169181612f5c565b600060208284031215612b26578081fd5b5035919050565b600080600060608486031215612b41578283fd5b505081359360208301359350604090920135919050565b60008060008060808587031215612b6d578384fd5b5050823594602084013594506040840135936060013592509050565b60008060408385031215612b9b578182fd5b8251612ba681612f47565b6020840151909250612bb781612f47565b809150509250929050565b600060208284031215612bd3578081fd5b5051919050565b60008060408385031215612bec578182fd5b50508035926020909101359150565b60008151808452815b81811015612c2057602081850181015186830182015201612c04565b81811115612c315782602083870101525b50601f01601f19169290920160200192915050565b6020808252825182820181905260009190848201906040850190845b81811015612c875783516001600160a01b031683529284019291840191600101612c62565b50909695505050505050565b82151581526040602082015260006124456040830184612bfb565b6020815260006116916020830184612bfb565b6020808252603c908201527f5468697320616374696f6e2063616e6e6f7420626520706572666f726d65642060408201527f7768696c652074686520636f6e74726163742069732070617573656400000000606082015260800190565b60006101008201905060018060a01b03808451168352602081818601511681850152816040860151166040850152606085015160608501526080850151608085015260a0850151915060a0840160005b6002811015612d8b57835182529282019290820190600101612d6e565b5050505060c083015160e083015292915050565b60008219821115612db257612db2612f1b565b500190565b600082612dc657612dc6612f31565b500490565b600181815b80851115612e06578160001904821115612dec57612dec612f1b565b80851615612df957918102915b93841c9390800290612dd0565b509250929050565b60006116918383600082612e2457506001610b7d565b81612e3157506000610b7d565b8160018114612e475760028114612e5157612e6d565b6001915050610b7d565b60ff841115612e6257612e62612f1b565b50506001821b610b7d565b5060208310610133831016604e8410600b8410161715612e90575081810a610b7d565b612e9a8383612dcb565b8060001904821115612eae57612eae612f1b565b029392505050565b6000816000190483118215151615612ed057612ed0612f1b565b500290565b600082821015612ee757612ee7612f1b565b500390565b6000600019821415612f0057612f00612f1b565b5060010190565b600082612f1657612f16612f31565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b6001600160a01b0381168114610b5657600080fd5b8015158114610b5657600080fdfea2646970667358221220095345f0a2f72fbca41f7b83f86109c1ce9fe318c207daf8e98db29f2c86fc2864736f6c63430008040033

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