Contract 0x57ddC52FE5967b7A82E69AA9b8925B30F2531032

 
Txn Hash Method
Block
From
To
Value
0xa7ffe1d57eea2f33fac8359fbaf4aeefbd6baf4b82788da16e1098f9823e2f1d0x60806040990658372023-05-17 10:59:08136 days 5 hrs agoThales: Deployer IN  Create: RangedMarketsAMM0 ETH0.0159670280960.001048154
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0x8bd6058c62a111afeb0e4ccb945bb1b6208da3b61b70df4df2dc3d2b9536e25d1075550882023-07-30 9:22:3362 days 7 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0xb6fdfac9591ed82b5fef5b2e6ef39c6998224b12915c12ae6a182aacb94bbc6d1075532112023-07-30 8:19:5962 days 8 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0xc902b49e95026d72fe3ced2c0b5c5158800de136e19a3fb43a04dc5ab8e3874f1075531792023-07-30 8:18:5562 days 8 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0xfb01817f2c1f6b6a6b24368f0ee4a5c324ae3d04b6eb162a211dcbd155d34fd61075527232023-07-30 8:03:4362 days 8 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0xc51b3c50636b8397d244fb2a4a74b639274bca4aa65af4b6d170dc491ab1177c1075526492023-07-30 8:01:1562 days 8 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0x21605eab376a565b16a3b95eb85f363f8acfe68a96be3b8895b34f70cdf447ea1075505322023-07-30 6:50:4162 days 10 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0x84d6b1428ea49ee50486df282fcbdcd71ba68b224671d3466a380b4805e194831075505182023-07-30 6:50:1362 days 10 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0xce9c529aac318ba67f294a5de83a0c13733e90132280bf8eeabff507b8ba23dc1075504952023-07-30 6:49:2762 days 10 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0x7d1b3401651138581652d0512f21d973646591a614ca7d39e767003f26ce2ae11075504802023-07-30 6:48:5762 days 10 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0x57873d4789224d272174b265264a2a1671619167d13e90eba195e796fa44e0351075498402023-07-30 6:27:3762 days 10 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0xce189fa7fcf8851758df3a89470ea316e322039ef35cc0d798ee23768509ad461075450022023-07-30 3:46:2162 days 13 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0xaade7bd508d1d688c6a4d1028599b8206628e3475fe161e959ed2910fb25bb621075427282023-07-30 2:30:3362 days 14 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0x3a9eb8d2f75973870ea9ed608cd4a81aa054d73a2984c64dd5c209c2d65be7391075425732023-07-30 2:25:2362 days 14 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0xe09ef2a3c5c5437e383d40b57be485967bcfb18df00252c614d7327bba1a7a711075421632023-07-30 2:11:4362 days 14 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0x100cee578354959d18a0e3e0840d6c94634950d788701ba8bf3b16154a76981b1075383562023-07-30 0:04:4962 days 16 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0x0383acca7a7a6815264ff57fc51f535c23b6334cb63e2fc118f8ac4e3d1b409d1075381082023-07-29 23:56:3362 days 16 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0x29b5da3800805a4295e18c79126b384343e5ec644d77eb3beca78409587213bf1075378812023-07-29 23:48:5962 days 17 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0x779c10801aac42391e3b066e201c4056ae460cfa4ef1c7a57a27428b4441fa7b1075374292023-07-29 23:33:5562 days 17 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0xe9b24a6ccaaf3e88b8c0dce1e8cfaf2298b9ae35145b64d07d1354632e75ad4b1075372962023-07-29 23:29:2962 days 17 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0xce8537b72d6e05ea6131394054e340ab6d46a8aada75c7f353ad6241adf4c1e31075372882023-07-29 23:29:1362 days 17 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0xd5f740d56fd3e4c8dcfbde82ac7efbcd58857f7f62d605909ca48fd353ccf9e41075368862023-07-29 23:15:4962 days 17 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0xddaa9423c5c6d430d9cd87836c9715cdf09f7c53bccee3648d5760b80607f7061075363182023-07-29 22:56:5362 days 17 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0xe7ba16a036f2c7f299f6de309ee1ccfd85c6d80d4328289e148d094122b0a7b81075355352023-07-29 22:30:4762 days 18 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0x5df7312f9a5e4acf67da6542f655dc3fefe267f409f891e9f97f4bd0f93433e41075329812023-07-29 21:05:3962 days 19 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
0x259fc11ee07b5d0683636d87d5c6b2d9dbcf9efc6016ff7a84b2f77b12d58b1e1075326652023-07-29 20:55:0762 days 20 hrs ago 0x2d356b114cbca8deff2d8783eac2a5a5324fe1df 0x57ddc52fe5967b7a82e69aa9b8925b30f25310320 ETH
[ Download CSV Export 
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.

Contract Source Code Verified (Exact Match)

Contract Name:
RangedMarketsAMM

Compiler Version
v0.8.4+commit.c7e474f2

Optimization Enabled:
Yes with 200 runs

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

// external
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-4.4.1/proxy/Clones.sol";

// interfaces
import "../interfaces/IPriceFeed.sol";
import "../interfaces/IThalesAMM.sol";

// internal
import "../utils/proxy/solidity-0.8.0/ProxyReentrancyGuard.sol";
import "../utils/proxy/solidity-0.8.0/ProxyOwned.sol";
import "../utils/proxy/solidity-0.8.0/ProxyPausable.sol";
import "../utils/libraries/AddressSetLib.sol";

import "./RangedPosition.sol";
import "./RangedPosition.sol";
import "./RangedMarket.sol";
import "../interfaces/IPositionalMarket.sol";
import "../interfaces/IStakingThales.sol";
import "../interfaces/IReferrals.sol";
import "../interfaces/ICurveSUSD.sol";

contract RangedMarketsAMM is Initializable, ProxyOwned, ProxyPausable, ProxyReentrancyGuard {
    using AddressSetLib for AddressSetLib.AddressSet;
    using SafeERC20Upgradeable for IERC20Upgradeable;

    uint private constant ONE = 1e18;
    uint private constant ONE_PERCENT = 1e16;

    IThalesAMM public thalesAmm;

    uint public rangedAmmFee;

    mapping(address => mapping(address => address)) public createdRangedMarkets;
    AddressSetLib.AddressSet internal _knownMarkets;

    address public rangedMarketMastercopy;
    address public rangedPositionMastercopy;

    IERC20Upgradeable public sUSD;

    mapping(address => uint) public spentOnMarket;

    // IMPORTANT: AMM risks only half or the payout effectively, but it risks the whole amount on price movements
    uint public capPerMarket;

    uint public minSupportedPrice;
    uint public maxSupportedPrice;

    address public safeBox;
    uint public safeBoxImpact;

    uint public minimalDifBetweenStrikes;

    IStakingThales public stakingThales;

    uint public maximalDifBetweenStrikes;

    address public referrals;
    uint public referrerFee;

    ICurveSUSD public curveSUSD;

    address public usdc;
    address public usdt;
    address public dai;

    bool public curveOnrampEnabled;
    uint public maxAllowedPegSlippagePercentage;

    function initialize(
        address _owner,
        IThalesAMM _thalesAmm,
        uint _rangedAmmFee,
        uint _capPerMarket,
        IERC20Upgradeable _sUSD,
        address _safeBox,
        uint _safeBoxImpact
    ) public initializer {
        setOwner(_owner);
        initNonReentrant();
        thalesAmm = _thalesAmm;
        capPerMarket = _capPerMarket;
        rangedAmmFee = _rangedAmmFee;
        sUSD = _sUSD;
        safeBox = _safeBox;
        safeBoxImpact = _safeBoxImpact;

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

    function createRangedMarket(address leftMarket, address rightMarket) external nonReentrant notPaused {
        _createRangedMarket(leftMarket, rightMarket);
    }

    function createRangedMarkets(address[] calldata leftMarkets, address[] calldata rightMarkets)
        external
        nonReentrant
        notPaused
    {
        require(
            leftMarkets.length > 0 && rightMarkets.length == leftMarkets.length,
            "Both arrays have to be non-empty and same size"
        );
        for (uint i = 0; i < leftMarkets.length; i++) {
            if (canCreateRangedMarket(leftMarkets[i], rightMarkets[i])) {
                _createRangedMarket(leftMarkets[i], rightMarkets[i]);
            }
        }
    }

    function canCreateRangedMarket(address leftMarket, address rightMarket) public view returns (bool toReturn) {
        if (thalesAmm.isMarketInAMMTrading(leftMarket) && thalesAmm.isMarketInAMMTrading(rightMarket)) {
            (uint maturityLeft, ) = IPositionalMarket(leftMarket).times();
            (uint maturityRight, ) = IPositionalMarket(rightMarket).times();
            (bytes32 leftkey, uint leftstrikePrice, ) = IPositionalMarket(leftMarket).getOracleDetails();
            (bytes32 rightkey, uint rightstrikePrice, ) = IPositionalMarket(rightMarket).getOracleDetails();

            if ((leftkey == rightkey) && (leftstrikePrice < rightstrikePrice) && (maturityLeft == maturityRight)) {
                if (!(((ONE + minimalDifBetweenStrikes * ONE_PERCENT) * leftstrikePrice) / ONE < rightstrikePrice)) {
                    toReturn = false;
                } else if (!(((ONE + maximalDifBetweenStrikes * ONE_PERCENT) * leftstrikePrice) / ONE > rightstrikePrice)) {
                    toReturn = false;
                } else {
                    toReturn = createdRangedMarkets[leftMarket][rightMarket] == address(0);
                }
            }
        }
    }

    function availableToBuyFromAMM(RangedMarket rangedMarket, RangedMarket.Position position)
        public
        view
        knownRangedMarket(address(rangedMarket))
        returns (uint)
    {
        uint availableLeft = thalesAmm.availableToBuyFromAMM(
            address(rangedMarket.leftMarket()),
            position == RangedMarket.Position.Out ? IThalesAMM.Position.Down : IThalesAMM.Position.Up
        );
        uint availableRight = thalesAmm.availableToBuyFromAMM(
            address(rangedMarket.rightMarket()),
            position == RangedMarket.Position.Out ? IThalesAMM.Position.Up : IThalesAMM.Position.Down
        );
        return availableLeft < availableRight ? availableLeft : availableRight;
    }

    function buyFromAmmQuote(
        RangedMarket rangedMarket,
        RangedMarket.Position position,
        uint amount
    ) public view knownRangedMarket(address(rangedMarket)) returns (uint sUSDPaid) {
        (sUSDPaid, , ) = buyFromAmmQuoteDetailed(rangedMarket, position, amount);
        uint basePrice = _transformCollateral((sUSDPaid * ONE) / amount, true);
        if (basePrice < minSupportedPrice || basePrice >= ONE) {
            sUSDPaid = 0;
        }
    }

    function buyFromAmmQuoteDetailed(
        RangedMarket rangedMarket,
        RangedMarket.Position position,
        uint amount
    )
        public
        view
        knownRangedMarket(address(rangedMarket))
        returns (
            uint quoteWithFees,
            uint leftQuote,
            uint rightQuote
        )
    {
        amount = position == RangedMarket.Position.Out ? amount : amount / 2;
        leftQuote = thalesAmm.buyFromAmmQuote(
            address(rangedMarket.leftMarket()),
            position == RangedMarket.Position.Out ? IThalesAMM.Position.Down : IThalesAMM.Position.Up,
            amount
        );
        rightQuote = thalesAmm.buyFromAmmQuote(
            address(rangedMarket.rightMarket()),
            position == RangedMarket.Position.Out ? IThalesAMM.Position.Up : IThalesAMM.Position.Down,
            amount
        );
        quoteWithFees = _buyFromAmmQuoteWithLeftAndRightQuote(position, amount, leftQuote, rightQuote);
    }

    function buyFromAmmQuoteWithDifferentCollateral(
        RangedMarket rangedMarket,
        RangedMarket.Position position,
        uint amount,
        address collateral
    ) public view returns (uint collateralQuote, uint sUSDToPay) {
        int128 curveIndex = _mapCollateralToCurveIndex(collateral);
        if (curveIndex > 0 && curveOnrampEnabled) {
            sUSDToPay = buyFromAmmQuote(rangedMarket, position, amount);
            //cant get a quote on how much collateral is needed from curve for sUSD,
            //so rather get how much of collateral you get for the sUSD quote and add 0.2% to that
            collateralQuote = (curveSUSD.get_dy_underlying(0, curveIndex, sUSDToPay) * (ONE + (ONE_PERCENT / 5))) / ONE;
        }
    }

    function buyFromAMMWithReferrer(
        RangedMarket rangedMarket,
        RangedMarket.Position position,
        uint amount,
        uint expectedPayout,
        uint additionalSlippage,
        address referrer
    ) public knownRangedMarket(address(rangedMarket)) nonReentrant notPaused {
        if (referrer != address(0)) {
            IReferrals(referrals).setReferrer(referrer, msg.sender);
        }
        _buyFromAMM(rangedMarket, position, amount, expectedPayout, additionalSlippage, true);
    }

    function buyFromAMMWithDifferentCollateralAndReferrer(
        RangedMarket rangedMarket,
        RangedMarket.Position position,
        uint amount,
        uint expectedPayout,
        uint additionalSlippage,
        address collateral,
        address _referrer
    ) public nonReentrant notPaused {
        if (_referrer != address(0)) {
            IReferrals(referrals).setReferrer(_referrer, msg.sender);
        }

        int128 curveIndex = _mapCollateralToCurveIndex(collateral);
        require(curveIndex > 0 && curveOnrampEnabled, "ID1");

        (uint collateralQuote, uint susdQuote) = buyFromAmmQuoteWithDifferentCollateral(
            rangedMarket,
            position,
            amount,
            collateral
        );

        uint transformedCollateralForPegCheck = collateral == usdc || collateral == usdt
            ? collateralQuote * 1e12
            : collateralQuote;
        require(
            maxAllowedPegSlippagePercentage > 0 &&
                transformedCollateralForPegCheck >= (susdQuote * (ONE - maxAllowedPegSlippagePercentage)) / ONE,
            "ID3"
        );

        require((collateralQuote * ONE) / expectedPayout <= (ONE + additionalSlippage), "ID2");

        IERC20Upgradeable(collateral).safeTransferFrom(msg.sender, address(this), collateralQuote);
        curveSUSD.exchange_underlying(curveIndex, 0, collateralQuote, susdQuote);

        _buyFromAMM(rangedMarket, position, amount, susdQuote, additionalSlippage, false);
    }

    function buyFromAMM(
        RangedMarket rangedMarket,
        RangedMarket.Position position,
        uint amount,
        uint expectedPayout,
        uint additionalSlippage
    ) public knownRangedMarket(address(rangedMarket)) nonReentrant notPaused {
        _buyFromAMM(rangedMarket, position, amount, expectedPayout, additionalSlippage, true);
    }

    function _buyFromAmmQuoteWithLeftAndRightQuote(
        RangedMarket.Position position,
        uint amount,
        uint leftQuote,
        uint rightQuote
    ) internal view returns (uint quoteWithFees) {
        if (leftQuote > 0 && rightQuote > 0) {
            uint summedQuotes = leftQuote + rightQuote;
            if (position == RangedMarket.Position.Out) {
                quoteWithFees = (summedQuotes * (rangedAmmFee + ONE)) / ONE;
            } else {
                if (
                    summedQuotes >
                    ((_transformCollateral(amount, false) - leftQuote) + (_transformCollateral(amount, false) - rightQuote))
                ) {
                    uint quoteWithoutFees = summedQuotes -
                        (_transformCollateral(amount, false) - leftQuote) -
                        (_transformCollateral(amount, false) - rightQuote);
                    quoteWithFees = (quoteWithoutFees * (rangedAmmFee + safeBoxImpact + ONE)) / ONE;
                }
            }
        }
    }

    function _buyFromAMM(
        RangedMarket rangedMarket,
        RangedMarket.Position position,
        uint amount,
        uint expectedPayout,
        uint additionalSlippage,
        bool sendSUSD
    ) internal {
        require(availableToBuyFromAMM(rangedMarket, position) >= amount, "ID4");

        uint sUSDPaid;
        address target;
        (RangedPosition inp, RangedPosition outp) = rangedMarket.positions();

        if (position == RangedMarket.Position.Out) {
            target = address(outp);
            sUSDPaid = _buyOUT(rangedMarket, amount);
        } else {
            target = address(inp);
            sUSDPaid = _buyIN(rangedMarket, amount);
            _handleSafeBoxFeeOnBuy(address(rangedMarket), amount, sUSDPaid);
        }

        uint basePrice = _transformCollateral((sUSDPaid * ONE) / amount, true);
        require(basePrice > minSupportedPrice && basePrice < ONE, "ID5");
        require(sUSDPaid > 0 && ((sUSDPaid * ONE) / expectedPayout <= (ONE + additionalSlippage)), "ID2");

        if (sendSUSD) {
            sUSD.safeTransferFrom(msg.sender, address(this), sUSDPaid);
        }

        rangedMarket.mint(amount, position, msg.sender);

        _handleReferrer(msg.sender, sUSDPaid);

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

        emit BoughtFromAmm(msg.sender, address(rangedMarket), position, amount, sUSDPaid, address(sUSD), target);

        (bytes32 leftkey, uint leftstrikePrice, ) = IPositionalMarket(rangedMarket.leftMarket()).getOracleDetails();
        (, uint rightstrikePrice, ) = IPositionalMarket(rangedMarket.rightMarket()).getOracleDetails();
        uint currentAssetPrice = thalesAmm.priceFeed().rateForCurrency(leftkey);
        bool inTheMoney = position == RangedMarket.Position.In
            ? currentAssetPrice >= leftstrikePrice && currentAssetPrice < rightstrikePrice
            : currentAssetPrice < leftstrikePrice || currentAssetPrice >= rightstrikePrice;
        emit BoughtOptionType(msg.sender, sUSDPaid, inTheMoney);
    }

    function _buyOUT(RangedMarket rangedMarket, uint amount) internal returns (uint) {
        uint paidLeft = thalesAmm.buyFromAMM(
            address(rangedMarket.leftMarket()),
            IThalesAMM.Position.Down,
            amount,
            type(uint256).max,
            0
        );

        uint paidRight = thalesAmm.buyFromAMM(
            address(rangedMarket.rightMarket()),
            IThalesAMM.Position.Up,
            amount,
            type(uint256).max,
            0
        );
        (, IPosition down) = IPositionalMarket(rangedMarket.leftMarket()).getOptions();
        IERC20Upgradeable(address(down)).safeTransfer(address(rangedMarket), amount);

        (IPosition up1, ) = IPositionalMarket(rangedMarket.rightMarket()).getOptions();
        IERC20Upgradeable(address(up1)).safeTransfer(address(rangedMarket), amount);
        return _buyFromAmmQuoteWithLeftAndRightQuote(RangedMarket.Position.Out, amount, paidLeft, paidRight);
    }

    function _buyIN(RangedMarket rangedMarket, uint amount) internal returns (uint) {
        uint paidLeft = thalesAmm.buyFromAMM(
            address(rangedMarket.leftMarket()),
            IThalesAMM.Position.Up,
            amount / 2,
            type(uint256).max,
            0
        );

        uint paidRight = thalesAmm.buyFromAMM(
            address(rangedMarket.rightMarket()),
            IThalesAMM.Position.Down,
            amount / 2,
            type(uint256).max,
            0
        );
        (IPosition up, ) = IPositionalMarket(rangedMarket.leftMarket()).getOptions();
        IERC20Upgradeable(address(up)).safeTransfer(address(rangedMarket), amount / 2);

        (, IPosition down1) = IPositionalMarket(rangedMarket.rightMarket()).getOptions();
        IERC20Upgradeable(address(down1)).safeTransfer(address(rangedMarket), amount / 2);

        return _buyFromAmmQuoteWithLeftAndRightQuote(RangedMarket.Position.In, amount / 2, paidLeft, paidRight);
    }

    function availableToSellToAMM(RangedMarket rangedMarket, RangedMarket.Position position)
        public
        view
        knownRangedMarket(address(rangedMarket))
        returns (uint _available)
    {
        uint availableLeft = thalesAmm.availableToSellToAMM(
            address(rangedMarket.leftMarket()),
            position == RangedMarket.Position.Out ? IThalesAMM.Position.Down : IThalesAMM.Position.Up
        );
        uint availableRight = thalesAmm.availableToSellToAMM(
            address(rangedMarket.rightMarket()),
            position == RangedMarket.Position.Out ? IThalesAMM.Position.Up : IThalesAMM.Position.Down
        );

        _available = availableLeft < availableRight ? availableLeft : availableRight;
        if (position == RangedMarket.Position.In) {
            _available = _available * 2;
        }
    }

    function sellToAmmQuote(
        RangedMarket rangedMarket,
        RangedMarket.Position position,
        uint amount
    ) public view knownRangedMarket(address(rangedMarket)) returns (uint pricePaid) {
        (pricePaid, , ) = sellToAmmQuoteDetailed(rangedMarket, position, amount);
    }

    function sellToAmmQuoteDetailed(
        RangedMarket rangedMarket,
        RangedMarket.Position position,
        uint amount
    )
        public
        view
        knownRangedMarket(address(rangedMarket))
        returns (
            uint quoteWithFees,
            uint leftQuote,
            uint rightQuote
        )
    {
        amount = position == RangedMarket.Position.Out ? amount : amount / 2;
        leftQuote = thalesAmm.sellToAmmQuote(
            address(rangedMarket.leftMarket()),
            position == RangedMarket.Position.Out ? IThalesAMM.Position.Down : IThalesAMM.Position.Up,
            amount
        );
        rightQuote = thalesAmm.sellToAmmQuote(
            address(rangedMarket.rightMarket()),
            position == RangedMarket.Position.Out ? IThalesAMM.Position.Up : IThalesAMM.Position.Down,
            amount
        );
        quoteWithFees = _sellToAmmQuoteDetailedWithLeftAndRightQuotes(position, amount, leftQuote, rightQuote);
    }

    function sellToAMM(
        RangedMarket rangedMarket,
        RangedMarket.Position position,
        uint amount,
        uint expectedPayout,
        uint additionalSlippage
    ) public knownRangedMarket(address(rangedMarket)) nonReentrant notPaused {
        uint pricePaid;

        _handleApprovals(rangedMarket);

        if (position == RangedMarket.Position.Out) {
            rangedMarket.burnOut(amount, msg.sender);
        } else {
            rangedMarket.burnIn(amount, msg.sender);
        }

        pricePaid = _handleSellToAmm(rangedMarket, position, amount);
        require(pricePaid > 0 && (expectedPayout * ONE) / pricePaid <= (ONE + additionalSlippage), "ID2");

        if (position == RangedMarket.Position.In) {
            _handleSafeBoxFeeOnSell(amount, rangedMarket, pricePaid);
        }

        sUSD.safeTransfer(msg.sender, pricePaid);

        _handleReferrer(msg.sender, pricePaid);

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

        (RangedPosition inp, RangedPosition outp) = rangedMarket.positions();
        address target = position == RangedMarket.Position.Out ? address(outp) : address(inp);
        emit SoldToAMM(msg.sender, address(rangedMarket), position, amount, pricePaid, address(sUSD), target);
    }

    /// @notice resolveRangedMarketsBatch resolve all markets in the batch
    /// @param markets the batch
    function resolveRangedMarketsBatch(address[] calldata markets) external {
        for (uint i = 0; i < markets.length; i++) {
            address market = markets[i];
            if (_knownMarkets.contains(market) && !RangedMarket(market).resolved()) {
                RangedMarket(market).resolveMarket();
            }
        }
    }

    function getPriceImpact(RangedMarket rangedMarket, RangedMarket.Position position) external view returns (int _impact) {
        int buyPriceImpactLeft = thalesAmm.buyPriceImpact(
            address(rangedMarket.leftMarket()),
            position == RangedMarket.Position.Out ? IThalesAMM.Position.Down : IThalesAMM.Position.Up,
            ONE
        );
        int buyPriceImpactRight = thalesAmm.buyPriceImpact(
            address(rangedMarket.rightMarket()),
            position == RangedMarket.Position.Out ? IThalesAMM.Position.Up : IThalesAMM.Position.Down,
            ONE
        );

        _impact = buyPriceImpactLeft + buyPriceImpactRight;
        if (position == RangedMarket.Position.Out) {
            _impact = _impact / 2;
        }
    }

    function _sellToAmmQuoteDetailedWithLeftAndRightQuotes(
        RangedMarket.Position position,
        uint amount,
        uint leftQuote,
        uint rightQuote
    ) internal view returns (uint quoteWithFees) {
        if (leftQuote > 0 && rightQuote > 0) {
            uint summedQuotes = leftQuote + rightQuote;
            if (position == RangedMarket.Position.Out) {
                quoteWithFees = (summedQuotes * (ONE - rangedAmmFee)) / ONE;
            } else {
                uint amountTransformed = _transformCollateral(amount, false);
                if (
                    amountTransformed > leftQuote &&
                    amountTransformed > rightQuote &&
                    summedQuotes > ((amountTransformed - leftQuote) + (amountTransformed - rightQuote))
                ) {
                    uint quoteWithoutFees = summedQuotes -
                        ((amountTransformed - leftQuote) + (amountTransformed - rightQuote));
                    quoteWithFees = (quoteWithoutFees * (ONE - rangedAmmFee - safeBoxImpact)) / ONE;
                }
            }
        }
    }

    function _handleSellToAmm(
        RangedMarket rangedMarket,
        RangedMarket.Position position,
        uint amount
    ) internal returns (uint) {
        uint baseAMMAmount = position == RangedMarket.Position.Out ? amount : amount / 2;
        uint sellLeft = thalesAmm.sellToAMM(
            address(rangedMarket.leftMarket()),
            position == RangedMarket.Position.Out ? IThalesAMM.Position.Down : IThalesAMM.Position.Up,
            baseAMMAmount,
            0,
            0
        );

        uint sellRight = thalesAmm.sellToAMM(
            address(rangedMarket.rightMarket()),
            position == RangedMarket.Position.Out ? IThalesAMM.Position.Up : IThalesAMM.Position.Down,
            baseAMMAmount,
            0,
            0
        );

        return _sellToAmmQuoteDetailedWithLeftAndRightQuotes(position, baseAMMAmount, sellLeft, sellRight);
    }

    function _handleApprovals(RangedMarket rangedMarket) internal {
        (IPosition up, IPosition down) = IPositionalMarket(rangedMarket.leftMarket()).getOptions();
        (IPosition up1, IPosition down1) = IPositionalMarket(rangedMarket.rightMarket()).getOptions();
        IERC20Upgradeable(address(up)).approve(address(thalesAmm), type(uint256).max);
        IERC20Upgradeable(address(down)).approve(address(thalesAmm), type(uint256).max);
        IERC20Upgradeable(address(up1)).approve(address(thalesAmm), type(uint256).max);
        IERC20Upgradeable(address(down1)).approve(address(thalesAmm), type(uint256).max);
    }

    function _handleReferrer(address buyer, uint sUSDPaid) internal {
        if (referrerFee > 0 && referrals != address(0)) {
            address referrer = IReferrals(referrals).referrals(buyer);
            if (referrer != address(0)) {
                uint referrerShare = (sUSDPaid * (ONE + referrerFee)) / ONE - sUSDPaid;
                sUSD.transfer(referrer, referrerShare);
                emit ReferrerPaid(referrer, buyer, referrerShare, sUSDPaid);
            }
        }
    }

    function _mapCollateralToCurveIndex(address collateral) internal view returns (int128) {
        if (collateral == dai) {
            return 1;
        }
        if (collateral == usdc) {
            return 2;
        }
        if (collateral == usdt) {
            return 3;
        }
        return 0;
    }

    function _handleSafeBoxFeeOnBuy(
        address rangedMarket,
        uint amount,
        uint sUSDPaid
    ) internal {
        uint safeBoxShare;
        if (safeBoxImpact > 0) {
            safeBoxShare = sUSDPaid - ((sUSDPaid * ONE) / (ONE + safeBoxImpact));
            sUSD.transfer(safeBox, safeBoxShare);
        }
    }

    function _handleSafeBoxFeeOnSell(
        uint amount,
        RangedMarket rangedMarket,
        uint sUSDPaid
    ) internal {
        uint safeBoxShare = 0;

        if (safeBoxImpact > 0) {
            safeBoxShare = ((sUSDPaid * ONE) / (ONE - safeBoxImpact)) - sUSDPaid;
            sUSD.transfer(safeBox, safeBoxShare);
        }
    }

    function _createRangedMarket(address leftMarket, address rightMarket) internal {
        require(canCreateRangedMarket(leftMarket, rightMarket), "Can't create such a ranged market!");

        RangedMarket rm = RangedMarket(Clones.clone(rangedMarketMastercopy));
        createdRangedMarkets[leftMarket][rightMarket] = address(rm);

        RangedPosition inp = RangedPosition(Clones.clone(rangedPositionMastercopy));
        inp.initialize(address(rm), "Position IN", "IN", address(this));

        RangedPosition outp = RangedPosition(Clones.clone(rangedPositionMastercopy));
        outp.initialize(address(rm), "Position OUT", "OUT", address(this));

        rm.initialize(leftMarket, rightMarket, address(inp), address(outp), address(this));

        _knownMarkets.add(address(rm));

        emit RangedMarketCreated(address(rm), leftMarket, rightMarket);
    }

    function _transformCollateral(uint collateral, bool reverse) internal view returns (uint transformed) {
        transformed = reverse
            ? IPositionalMarketManager(thalesAmm.manager()).reverseTransformCollateral(collateral)
            : IPositionalMarketManager(thalesAmm.manager()).transformCollateral(collateral);
    }

    function transferSusdTo(address receiver, uint amount) external {
        require(_knownMarkets.contains(msg.sender), "Not a known ranged market");
        sUSD.safeTransfer(receiver, amount);
    }

    function retrieveSUSDAmount(address payable account, uint amount) external onlyOwner {
        sUSD.safeTransfer(account, amount);
    }

    function setRangedMarketMastercopies(address _rangedMarketMastercopy, address _rangedPositionMastercopy)
        external
        onlyOwner
    {
        rangedMarketMastercopy = _rangedMarketMastercopy;
        rangedPositionMastercopy = _rangedPositionMastercopy;
    }

    function setMinMaxSupportedPrice(
        uint _minSupportedPrice,
        uint _maxSupportedPrice,
        uint _minDiffBetweenStrikes,
        uint _maxDiffBetweenStrikes
    ) public onlyOwner {
        minSupportedPrice = _minSupportedPrice;
        maxSupportedPrice = _maxSupportedPrice;
        minimalDifBetweenStrikes = _minDiffBetweenStrikes;
        maximalDifBetweenStrikes = _maxDiffBetweenStrikes;
        emit SetMinMaxSupportedPrice(minSupportedPrice, maxSupportedPrice);
        emit SetMinimalMaximalDifBetweenStrikes(minimalDifBetweenStrikes, maximalDifBetweenStrikes);
    }

    function setSafeBoxDataAndRangedAMMFee(
        address _safeBox,
        uint _safeBoxImpact,
        uint _rangedAMMFee
    ) external onlyOwner {
        safeBoxImpact = _safeBoxImpact;
        safeBox = _safeBox;
        emit SafeBoxChanged(_safeBoxImpact, _safeBox);
        rangedAmmFee = _rangedAMMFee;
        emit SetRangedFee(rangedAmmFee);
    }

    function setThalesAMMStakingThalesAndReferrals(
        address _thalesAMM,
        IStakingThales _stakingThales,
        address _referrals,
        uint _referrerFee
    ) external onlyOwner {
        thalesAmm = IThalesAMM(_thalesAMM);
        sUSD.approve(address(thalesAmm), type(uint256).max);
        stakingThales = _stakingThales;
        referrals = _referrals;
        referrerFee = _referrerFee;
    }

    function setCurveSUSD(bool _curveOnrampEnabled, uint _maxAllowedPegSlippagePercentage) external onlyOwner {
        curveOnrampEnabled = _curveOnrampEnabled;
        maxAllowedPegSlippagePercentage = _maxAllowedPegSlippagePercentage;
    }

    modifier knownRangedMarket(address market) {
        require(_knownMarkets.contains(market), "Not a known ranged market");
        _;
    }

    event SoldToAMM(
        address seller,
        address market,
        RangedMarket.Position position,
        uint amount,
        uint sUSDPaid,
        address susd,
        address asset
    );
    event BoughtFromAmm(
        address buyer,
        address market,
        RangedMarket.Position position,
        uint amount,
        uint sUSDPaid,
        address susd,
        address asset
    );
    event BoughtOptionType(address buyer, uint sUSDPaid, bool inTheMoney);

    event RangedMarketCreated(address market, address leftMarket, address rightMarket);
    event SafeBoxChanged(uint _safeBoxImpact, address _safeBox);
    event SetMinMaxSupportedPrice(uint minSupportedPrice, uint maxSupportedPrice);
    event SetMinimalMaximalDifBetweenStrikes(uint minSupportedPrice, uint maxSupportedPrice);
    event SetRangedFee(uint rangedAmmFee);
    event ReferrerPaid(address refferer, address trader, uint amount, uint volume);
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

File 3 of 29 : MathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/math/Math.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

File 5 of 29 : 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 6 of 29 : SafeMathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (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 SafeMathUpgradeable {
    /**
     * @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 substraction 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 7 of 29 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

    bool private _paused;

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

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

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

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

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

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

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

File 9 of 29 : 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 10 of 29 : 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 11 of 29 : 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 12 of 29 : ProxyReentrancyGuard.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

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

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

File 13 of 29 : 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 14 of 29 : 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 15 of 29 : 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 16 of 29 : RangedPosition.sol
// in position collaterized by 0.5 UP on the left leg and 0.5 DOWN on the right leg

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

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

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

contract RangedPosition is IERC20 {
    /* ========== STATE VARIABLES ========== */

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

    RangedMarket public rangedMarket;

    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 thalesRangedAMM;
    /* ========== CONSTRUCTOR ========== */

    bool public initialized = false;

    function initialize(
        address market,
        string calldata _name,
        string calldata _symbol,
        address _thalesRangedAMM
    ) external {
        require(!initialized, "Ranged Market already initialized");
        initialized = true;
        rangedMarket = RangedMarket(market);
        name = _name;
        symbol = _symbol;
        thalesRangedAMM = _thalesRangedAMM;
    }

    function allowance(address owner, address spender) external view override returns (uint256) {
        if (spender == thalesRangedAMM) {
            return type(uint256).max;
        } else {
            return allowances[owner][spender];
        }
    }

    function burn(address claimant, uint amount) external onlyRangedMarket {
        balanceOf[claimant] = balanceOf[claimant] - amount;
        totalSupply = totalSupply - amount;
        emit Burned(claimant, amount);
        emit Transfer(claimant, address(0), amount);
    }

    function mint(address minter, uint amount) external onlyRangedMarket {
        _requireMinimumAmount(amount);
        totalSupply = totalSupply + amount;
        balanceOf[minter] = balanceOf[minter] + amount; // Increment rather than assigning since a transfer may have occurred.
        emit Mint(minter, amount);
        emit Transfer(address(0), minter, amount);
    }

    /* ---------- ERC20 Functions ---------- */

    function _transfer(
        address _from,
        address _to,
        uint _value
    ) internal returns (bool success) {
        require(_to != address(0) && _to != address(this), "Invalid address");

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

        balanceOf[_from] = fromBalance - _value;
        balanceOf[_to] = balanceOf[_to] + _value;

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

    function transfer(address _to, uint _value) external override returns (bool success) {
        return _transfer(msg.sender, _to, _value);
    }

    function transferFrom(
        address _from,
        address _to,
        uint _value
    ) external override returns (bool success) {
        if (msg.sender != thalesRangedAMM) {
            uint fromAllowance = allowances[_from][msg.sender];
            require(_value <= fromAllowance, "Insufficient allowance");
            allowances[_from][msg.sender] = fromAllowance - _value;
        }
        return _transfer(_from, _to, _value);
    }

    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;
    }

    function getBalanceOf(address account) external view returns (uint) {
        return balanceOf[account];
    }

    function getTotalSupply() external view returns (uint) {
        return totalSupply;
    }

    modifier onlyRangedMarket {
        require(msg.sender == address(rangedMarket), "only the Ranged Market may perform these methods");
        _;
    }

    function _requireMinimumAmount(uint amount) internal pure returns (uint) {
        require(amount >= _MINIMUM_AMOUNT || amount == 0, "Balance < $0.01");
        return amount;
    }

    event Mint(address minter, uint amount);
    event Burned(address burner, uint amount);
}

File 17 of 29 : RangedMarket.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-4.4.1/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts-4.4.1/token/ERC20/utils/SafeERC20.sol";

// Internal references
import "./RangedPosition.sol";
import "./RangedMarketsAMM.sol";
import "../interfaces/IPositionalMarket.sol";
import "../interfaces/IPositionalMarketManager.sol";

contract RangedMarket {
    using SafeERC20 for IERC20;

    enum Position {In, Out}

    IPositionalMarket public leftMarket;
    IPositionalMarket public rightMarket;

    struct Positions {
        RangedPosition inp;
        RangedPosition outp;
    }

    Positions public positions;

    RangedMarketsAMM public rangedMarketsAMM;

    bool public resolved = false;

    uint finalPrice;

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

    bool public initialized = false;

    function initialize(
        address _leftMarket,
        address _rightMarket,
        address _in,
        address _out,
        address _rangedMarketsAMM
    ) external {
        require(!initialized, "Ranged Market already initialized");
        initialized = true;
        leftMarket = IPositionalMarket(_leftMarket);
        rightMarket = IPositionalMarket(_rightMarket);
        positions.inp = RangedPosition(_in);
        positions.outp = RangedPosition(_out);
        rangedMarketsAMM = RangedMarketsAMM(_rangedMarketsAMM);
    }

    function mint(
        uint value,
        Position _position,
        address minter
    ) external onlyAMM {
        if (value == 0) {
            return;
        }
        _mint(minter, value, _position);
    }

    function _mint(
        address minter,
        uint amount,
        Position _position
    ) internal {
        if (_position == Position.In) {
            positions.inp.mint(minter, amount);
        } else {
            positions.outp.mint(minter, amount);
        }
        emit Mint(minter, amount, _position);
    }

    function burnIn(uint value, address claimant) external onlyAMM {
        if (value == 0) {
            return;
        }
        (IPosition up, ) = IPositionalMarket(leftMarket).getOptions();
        IERC20(address(up)).safeTransfer(msg.sender, value / 2);

        (, IPosition down1) = IPositionalMarket(rightMarket).getOptions();
        IERC20(address(down1)).safeTransfer(msg.sender, value / 2);

        positions.inp.burn(claimant, value);
        emit Burn(claimant, value, Position.In);
    }

    function burnOut(uint value, address claimant) external onlyAMM {
        if (value == 0) {
            return;
        }
        (, IPosition down) = IPositionalMarket(leftMarket).getOptions();
        IERC20(address(down)).safeTransfer(msg.sender, value);

        (IPosition up1, ) = IPositionalMarket(rightMarket).getOptions();
        IERC20(address(up1)).safeTransfer(msg.sender, value);

        positions.outp.burn(claimant, value);

        emit Burn(claimant, value, Position.Out);
    }

    function canExercisePositions() external view returns (bool) {
        if (!leftMarket.resolved() && !leftMarket.canResolve()) {
            return false;
        }
        if (!rightMarket.resolved() && !rightMarket.canResolve()) {
            return false;
        }

        uint inBalance = positions.inp.balanceOf(msg.sender);
        uint outBalance = positions.outp.balanceOf(msg.sender);

        if (inBalance == 0 && outBalance == 0) {
            return false;
        }

        return true;
    }

    function exercisePositions() external {
        if (leftMarket.canResolve()) {
            IPositionalMarketManager(rangedMarketsAMM.thalesAmm().manager()).resolveMarket(address(leftMarket));
        }
        if (rightMarket.canResolve()) {
            IPositionalMarketManager(rangedMarketsAMM.thalesAmm().manager()).resolveMarket(address(rightMarket));
        }
        require(leftMarket.resolved() && rightMarket.resolved(), "Left or Right market not resolved yet!");

        uint inBalance = positions.inp.balanceOf(msg.sender);
        uint outBalance = positions.outp.balanceOf(msg.sender);

        require(inBalance != 0 || outBalance != 0, "Nothing to exercise");

        if (!resolved) {
            resolveMarket();
        }

        // Each option only needs to be exercised if the account holds any of it.
        if (inBalance != 0) {
            positions.inp.burn(msg.sender, inBalance);
        }
        if (outBalance != 0) {
            positions.outp.burn(msg.sender, outBalance);
        }

        Position curResult = Position.Out;
        if ((leftMarket.result() == IPositionalMarket.Side.Up) && (rightMarket.result() == IPositionalMarket.Side.Down)) {
            curResult = Position.In;
        }

        // Only pay out the side that won.
        uint payout = (curResult == Position.In) ? inBalance : outBalance;
        if (payout != 0) {
            rangedMarketsAMM.transferSusdTo(
                msg.sender,
                IPositionalMarketManager(rangedMarketsAMM.thalesAmm().manager()).transformCollateral(payout)
            );
        }
        emit Exercised(msg.sender, payout, curResult);
    }

    function canResolve() external view returns (bool) {
        // The markets must be resolved
        if (!leftMarket.resolved() && !leftMarket.canResolve()) {
            return false;
        }
        if (!rightMarket.resolved() && !rightMarket.canResolve()) {
            return false;
        }

        return !resolved;
    }

    function resolveMarket() public {
        // The markets must be resolved
        if (leftMarket.canResolve()) {
            IPositionalMarketManager(rangedMarketsAMM.thalesAmm().manager()).resolveMarket(address(leftMarket));
        }
        if (rightMarket.canResolve()) {
            IPositionalMarketManager(rangedMarketsAMM.thalesAmm().manager()).resolveMarket(address(rightMarket));
        }
        require(leftMarket.resolved() && rightMarket.resolved(), "Left or Right market not resolved yet!");
        require(!resolved, "Already resolved!");

        if (positions.inp.totalSupply() > 0 || positions.outp.totalSupply() > 0) {
            leftMarket.exerciseOptions();
            rightMarket.exerciseOptions();
        }
        resolved = true;

        if (rangedMarketsAMM.sUSD().balanceOf(address(this)) > 0) {
            rangedMarketsAMM.sUSD().transfer(address(rangedMarketsAMM), rangedMarketsAMM.sUSD().balanceOf(address(this)));
        }

        (, , uint _finalPrice) = leftMarket.getOracleDetails();
        finalPrice = _finalPrice;
        emit Resolved(result(), finalPrice);
    }

    function result() public view returns (Position resultToReturn) {
        resultToReturn = Position.Out;
        if ((leftMarket.result() == IPositionalMarket.Side.Up) && (rightMarket.result() == IPositionalMarket.Side.Down)) {
            resultToReturn = Position.In;
        }
    }

    function withdrawCollateral(address recipient) external onlyAMM {
        rangedMarketsAMM.sUSD().transfer(recipient, rangedMarketsAMM.sUSD().balanceOf(address(this)));
    }

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

    event Mint(address minter, uint amount, Position _position);
    event Burn(address burner, uint amount, Position _position);
    event Exercised(address exerciser, uint amount, Position _position);
    event Resolved(Position winningPosition, uint finalPrice);
}

File 18 of 29 : 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 19 of 29 : IStakingThales.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.5.16;

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

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

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

    function currentPeriodRewards() external view returns (uint);

    function currentPeriodFees() external view returns (uint);

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

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

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

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

    function getContractRewardFunds() external view returns (uint);

    function getContractFeeFunds() external view returns (uint);

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

File 20 of 29 : IReferrals.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.16;

interface IReferrals {
    function referrals(address) external view returns (address);

    function sportReferrals(address) external view returns (address);

    function setReferrer(address, address) external;
}

File 21 of 29 : ICurveSUSD.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.16;

interface ICurveSUSD {
    function exchange_underlying(
        int128 i,
        int128 j,
        uint256 _dx,
        uint256 _min_dy
    ) external returns (uint256);

    function get_dy_underlying(
        int128 i,
        int128 j,
        uint256 _dx
    ) external view returns (uint256);

    //    @notice Perform an exchange between two underlying coins
    //    @param i Index value for the underlying coin to send
    //    @param j Index valie of the underlying coin to receive
    //    @param _dx Amount of `i` being exchanged
    //    @param _min_dy Minimum amount of `j` to receive
    //    @param _receiver Address that receives `j`
    //    @return Actual amount of `j` received

    // indexes:
    // 0 = sUSD 18 dec 0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9
    // 1= DAI 18 dec 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1
    // 2= USDC 6 dec 0x7F5c764cBc14f9669B88837ca1490cCa17c31607
    // 3= USDT 6 dec 0x94b008aA00579c1307B0EF2c499aD98a8ce58e58
}

File 22 of 29 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

File 24 of 29 : 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 25 of 29 : 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 26 of 29 : 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 27 of 29 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

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

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

File 28 of 29 : draft-IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

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

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

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

File 29 of 29 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://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 Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

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

        (bool success, bytes memory returndata) = target.delegatecall(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
                /// @solidity memory-safe-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 Security Audit

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"buyer","type":"address"},{"indexed":false,"internalType":"address","name":"market","type":"address"},{"indexed":false,"internalType":"enum RangedMarket.Position","name":"position","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sUSDPaid","type":"uint256"},{"indexed":false,"internalType":"address","name":"susd","type":"address"},{"indexed":false,"internalType":"address","name":"asset","type":"address"}],"name":"BoughtFromAmm","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"buyer","type":"address"},{"indexed":false,"internalType":"uint256","name":"sUSDPaid","type":"uint256"},{"indexed":false,"internalType":"bool","name":"inTheMoney","type":"bool"}],"name":"BoughtOptionType","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":"address","name":"market","type":"address"},{"indexed":false,"internalType":"address","name":"leftMarket","type":"address"},{"indexed":false,"internalType":"address","name":"rightMarket","type":"address"}],"name":"RangedMarketCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"refferer","type":"address"},{"indexed":false,"internalType":"address","name":"trader","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"volume","type":"uint256"}],"name":"ReferrerPaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_safeBoxImpact","type":"uint256"},{"indexed":false,"internalType":"address","name":"_safeBox","type":"address"}],"name":"SafeBoxChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"minSupportedPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"maxSupportedPrice","type":"uint256"}],"name":"SetMinMaxSupportedPrice","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"minSupportedPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"maxSupportedPrice","type":"uint256"}],"name":"SetMinimalMaximalDifBetweenStrikes","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"rangedAmmFee","type":"uint256"}],"name":"SetRangedFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"seller","type":"address"},{"indexed":false,"internalType":"address","name":"market","type":"address"},{"indexed":false,"internalType":"enum RangedMarket.Position","name":"position","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sUSDPaid","type":"uint256"},{"indexed":false,"internalType":"address","name":"susd","type":"address"},{"indexed":false,"internalType":"address","name":"asset","type":"address"}],"name":"SoldToAMM","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract RangedMarket","name":"rangedMarket","type":"address"},{"internalType":"enum RangedMarket.Position","name":"position","type":"uint8"}],"name":"availableToBuyFromAMM","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract RangedMarket","name":"rangedMarket","type":"address"},{"internalType":"enum RangedMarket.Position","name":"position","type":"uint8"}],"name":"availableToSellToAMM","outputs":[{"internalType":"uint256","name":"_available","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract RangedMarket","name":"rangedMarket","type":"address"},{"internalType":"enum RangedMarket.Position","name":"position","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"expectedPayout","type":"uint256"},{"internalType":"uint256","name":"additionalSlippage","type":"uint256"}],"name":"buyFromAMM","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract RangedMarket","name":"rangedMarket","type":"address"},{"internalType":"enum RangedMarket.Position","name":"position","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"expectedPayout","type":"uint256"},{"internalType":"uint256","name":"additionalSlippage","type":"uint256"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"address","name":"_referrer","type":"address"}],"name":"buyFromAMMWithDifferentCollateralAndReferrer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract RangedMarket","name":"rangedMarket","type":"address"},{"internalType":"enum RangedMarket.Position","name":"position","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"expectedPayout","type":"uint256"},{"internalType":"uint256","name":"additionalSlippage","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"}],"name":"buyFromAMMWithReferrer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract RangedMarket","name":"rangedMarket","type":"address"},{"internalType":"enum RangedMarket.Position","name":"position","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"buyFromAmmQuote","outputs":[{"internalType":"uint256","name":"sUSDPaid","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract RangedMarket","name":"rangedMarket","type":"address"},{"internalType":"enum RangedMarket.Position","name":"position","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"buyFromAmmQuoteDetailed","outputs":[{"internalType":"uint256","name":"quoteWithFees","type":"uint256"},{"internalType":"uint256","name":"leftQuote","type":"uint256"},{"internalType":"uint256","name":"rightQuote","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract RangedMarket","name":"rangedMarket","type":"address"},{"internalType":"enum RangedMarket.Position","name":"position","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"collateral","type":"address"}],"name":"buyFromAmmQuoteWithDifferentCollateral","outputs":[{"internalType":"uint256","name":"collateralQuote","type":"uint256"},{"internalType":"uint256","name":"sUSDToPay","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"leftMarket","type":"address"},{"internalType":"address","name":"rightMarket","type":"address"}],"name":"canCreateRangedMarket","outputs":[{"internalType":"bool","name":"toReturn","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"capPerMarket","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"leftMarket","type":"address"},{"internalType":"address","name":"rightMarket","type":"address"}],"name":"createRangedMarket","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"leftMarkets","type":"address[]"},{"internalType":"address[]","name":"rightMarkets","type":"address[]"}],"name":"createRangedMarkets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"createdRangedMarkets","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"curveOnrampEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"curveSUSD","outputs":[{"internalType":"contract ICurveSUSD","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dai","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract RangedMarket","name":"rangedMarket","type":"address"},{"internalType":"enum RangedMarket.Position","name":"position","type":"uint8"}],"name":"getPriceImpact","outputs":[{"internalType":"int256","name":"_impact","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initNonReentrant","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"contract IThalesAMM","name":"_thalesAmm","type":"address"},{"internalType":"uint256","name":"_rangedAmmFee","type":"uint256"},{"internalType":"uint256","name":"_capPerMarket","type":"uint256"},{"internalType":"contract IERC20Upgradeable","name":"_sUSD","type":"address"},{"internalType":"address","name":"_safeBox","type":"address"},{"internalType":"uint256","name":"_safeBoxImpact","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastPauseTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxAllowedPegSlippagePercentage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSupportedPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maximalDifBetweenStrikes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minSupportedPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minimalDifBetweenStrikes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"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":"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":"rangedAmmFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rangedMarketMastercopy","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rangedPositionMastercopy","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"referrals","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"referrerFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"markets","type":"address[]"}],"name":"resolveRangedMarketsBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"retrieveSUSDAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sUSD","outputs":[{"internalType":"contract IERC20Upgradeable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"safeBox","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"safeBoxImpact","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract RangedMarket","name":"rangedMarket","type":"address"},{"internalType":"enum RangedMarket.Position","name":"position","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"expectedPayout","type":"uint256"},{"internalType":"uint256","name":"additionalSlippage","type":"uint256"}],"name":"sellToAMM","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract RangedMarket","name":"rangedMarket","type":"address"},{"internalType":"enum RangedMarket.Position","name":"position","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"sellToAmmQuote","outputs":[{"internalType":"uint256","name":"pricePaid","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract RangedMarket","name":"rangedMarket","type":"address"},{"internalType":"enum RangedMarket.Position","name":"position","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"sellToAmmQuoteDetailed","outputs":[{"internalType":"uint256","name":"quoteWithFees","type":"uint256"},{"internalType":"uint256","name":"leftQuote","type":"uint256"},{"internalType":"uint256","name":"rightQuote","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"_curveOnrampEnabled","type":"bool"},{"internalType":"uint256","name":"_maxAllowedPegSlippagePercentage","type":"uint256"}],"name":"setCurveSUSD","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_minSupportedPrice","type":"uint256"},{"internalType":"uint256","name":"_maxSupportedPrice","type":"uint256"},{"internalType":"uint256","name":"_minDiffBetweenStrikes","type":"uint256"},{"internalType":"uint256","name":"_maxDiffBetweenStrikes","type":"uint256"}],"name":"setMinMaxSupportedPrice","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":"_rangedMarketMastercopy","type":"address"},{"internalType":"address","name":"_rangedPositionMastercopy","type":"address"}],"name":"setRangedMarketMastercopies","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_safeBox","type":"address"},{"internalType":"uint256","name":"_safeBoxImpact","type":"uint256"},{"internalType":"uint256","name":"_rangedAMMFee","type":"uint256"}],"name":"setSafeBoxDataAndRangedAMMFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_thalesAMM","type":"address"},{"internalType":"contract IStakingThales","name":"_stakingThales","type":"address"},{"internalType":"address","name":"_referrals","type":"address"},{"internalType":"uint256","name":"_referrerFee","type":"uint256"}],"name":"setThalesAMMStakingThalesAndReferrals","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"spentOnMarket","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stakingThales","outputs":[{"internalType":"contract IStakingThales","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"thalesAmm","outputs":[{"internalType":"contract IThalesAMM","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"proxyAddress","type":"address"}],"name":"transferOwnershipAtInit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferSusdTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"usdc","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"usdt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

608060405234801561001057600080fd5b50615f9680620000216000396000f3fe608060405234801561001057600080fd5b50600436106103835760003560e01c80638da5cb5b116101de578063ca5d220d1161010f578063e2293fe2116100ad578063efc152511161007c578063efc15251146107a8578063f4b9fa75146107bb578063fb91d41c146107ce578063fd8a8cc6146107d757600080fd5b8063e2293fe214610750578063ebc7977214610784578063ef7263f21461078c578063efb1fe351461079557600080fd5b8063d3dc7539116100e9578063d3dc7539146106f9578063d4a2641b1461070c578063d69fb66814610734578063dfa5f1f61461073d57600080fd5b8063ca5d220d146106ca578063ce7f0de2146106dd578063ce7f8b03146106f057600080fd5b8063a5bf660d1161017c578063c2783f9211610156578063c2783f9214610671578063c3b83f5f14610684578063c4dc27d714610697578063c70b45c4146106b757600080fd5b8063a5bf660d14610638578063ad2eb81c1461064b578063c1ddbe171461065e57600080fd5b80639324cac7116101b85780639324cac7146105ec578063957b0071146105ff5780639f916c9f146106125780639fdfc5c41461062557600080fd5b80638da5cb5b146105c157806391b4ded9146105da578063931b2040146105e357600080fd5b806347fdb1b3116102b85780636cc5a6ff1161025657806379ba50971161023057806379ba5097146105655780637cde91161461056d5780638875eb8414610580578063896d5dda1461059357600080fd5b80636cc5a6ff146105365780636e88a7bd146105495780637844dd481461055257600080fd5b806353a47bb71161029257806353a47bb7146104f05780635a4c6dce146105035780635c975abb146105165780636bd6529c1461052357600080fd5b806347fdb1b3146104bc57806348663e95146104c55780634ee7dbe2146104d857600080fd5b80631fbb38e8116103255780632909f51a116102ff5780632909f51a1461047a5780632f48ab7d146104835780633ce1108d146104965780633e413bee146104a957600080fd5b80631fbb38e8146104185780632626eb2a1461043c578063270e13ef1461046757600080fd5b806313af40351161036157806313af4035146103d65780631627540c146103e957806316c38b3c146103fc57806319b844a61461040f57600080fd5b80630c174e7b146103885780630c75f44f1461039d5780630f13aae8146103b0575b600080fd5b61039b61039636600461570f565b6107ea565b005b61039b6103ab366004615687565b610999565b6103c36103be36600461595c565b6109cf565b6040519081526020015b60405180910390f35b61039b6103e4366004615624565b610a10565b61039b6103f7366004615624565b610b4b565b61039b61040a366004615878565b610ba1565b6103c360105481565b601b5461042c90600160a01b900460ff1681565b60405190151581526020016103cd565b600b5461044f906001600160a01b031681565b6040516001600160a01b0390911681526020016103cd565b6103c361047536600461595c565b610c17565b6103c3601c5481565b601a5461044f906001600160a01b031681565b61039b6104a43660046159e9565b610ca8565b60195461044f906001600160a01b031681565b6103c360155481565b60115461044f906001600160a01b031681565b60055461044f9061010090046001600160a01b031681565b60015461044f906001600160a01b031681565b61039b610511366004615789565b611062565b60035461042c9060ff1681565b61039b61053136600461580f565b6110a4565b61039b610544366004615a9b565b61127d565b6103c360175481565b6103c3610560366004615928565b611589565b61039b611856565b61039b61057b366004615687565b611953565b61039b61058e3660046159e9565b6119c1565b6105a66105a136600461595c565b611a57565b604080519384526020840192909252908201526060016103cd565b60005461044f906201000090046001600160a01b031681565b6103c360025481565b6103c3600f5481565b600c5461044f906001600160a01b031681565b6105a661060d36600461595c565b611d44565b61039b610620366004615a37565b612025565b61039b6106333660046157cf565b612130565b60185461044f906001600160a01b031681565b600a5461044f906001600160a01b031681565b61039b61066c3660046156bf565b612265565b6103c361067f366004615928565b61234c565b61039b610692366004615624565b612634565b6103c36106a5366004615624565b600d6020526000908152604090205481565b61039b6106c53660046158b0565b61274d565b61039b6106d8366004615b4e565b612777565b61039b6106eb36600461579b565b612818565b6103c360135481565b60165461044f906001600160a01b031681565b61071f61071a366004615999565b6128ba565b604080519283526020830191909152016103cd565b6103c360125481565b61042c61074b366004615687565b6129d3565b61044f61075e366004615687565b60076020908152600092835260408084209091529082529020546001600160a01b031681565b61039b612dc0565b6103c360065481565b61039b6107a336600461565c565b612e1e565b6103c36107b6366004615928565b612e26565b601b5461044f906001600160a01b031681565b6103c3600e5481565b60145461044f906001600160a01b031681565b600054610100900460ff166108055760005460ff1615610809565b303b155b6108715760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b600054610100900460ff16158015610893576000805461ffff19166101011790555b61089c88610a10565b6108a4612dc0565b60058054610100600160a81b0319166101006001600160a01b038a811682029290921792839055600e8890556006899055600c80546001600160a01b031990811689851690811790925560118054909116888516179055601286905560405163095ea7b360e01b8152909363095ea7b39361092a93909104169060001990600401615c78565b602060405180830381600087803b15801561094457600080fd5b505af1158015610958573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061097c9190615894565b50801561098f576000805461ff00191690555b5050505050505050565b6109a16130d4565b600a80546001600160a01b039384166001600160a01b031991821617909155600b8054929093169116179055565b6000836109dd60088261314e565b6109f95760405162461bcd60e51b815260040161086890615cc4565b610a04858585611a57565b50909695505050505050565b6001600160a01b038116610a665760405162461bcd60e51b815260206004820152601960248201527f4f776e657220616464726573732063616e6e6f742062652030000000000000006044820152606401610868565b600154600160a01b900460ff1615610ad25760405162461bcd60e51b815260206004820152602960248201527f416c726561647920696e697469616c697a65642c20757365206e6f6d696e617460448201526832a732bba7bbb732b960b91b6064820152608401610868565b6001805460ff60a01b1916600160a01b179055600080546001600160a01b03831662010000810262010000600160b01b03199092169190911782556040805192835260208301919091527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c91015b60405180910390a150565b610b536130d4565b600180546001600160a01b0319166001600160a01b0383169081179091556040519081527f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce2290602001610b40565b610ba96130d4565b60035460ff1615158115151415610bbd5750565b6003805460ff191682151590811790915560ff1615610bdb57426002555b60035460405160ff909116151581527f8fb6c181ee25a520cf3dd6565006ef91229fcfe5a989566c2a3b8c115570cec590602001610b40565b50565b600083610c2560088261314e565b610c415760405162461bcd60e51b815260040161086890615cc4565b610c4c858585611d44565b5090925060009050610c7b84610c6a670de0b6b3a764000086615e76565b610c749190615e62565b60016131d0565b9050600f54811080610c955750670de0b6b3a76400008110155b15610c9f57600092505b50509392505050565b84610cb460088261314e565b610cd05760405162461bcd60e51b815260040161086890615cc4565b600160046000828254610ce39190615e1c565b909155505060045460035460ff1615610d0e5760405162461bcd60e51b815260040161086890615cfb565b6000610d19886133e9565b6001876001811115610d3b57634e487b7160e01b600052602160045260246000fd5b1415610da657604051637f28391960e11b8152600481018790523360248201526001600160a01b0389169063fe50723290604401600060405180830381600087803b158015610d8957600080fd5b505af1158015610d9d573d6000803e3d6000fd5b50505050610e07565b604051633e3f745f60e21b8152600481018790523360248201526001600160a01b0389169063f8fdd17c90604401600060405180830381600087803b158015610dee57600080fd5b505af1158015610e02573d6000803e3d6000fd5b505050505b610e128888886137fa565b9050600081118015610e515750610e3184670de0b6b3a7640000615e1c565b81610e44670de0b6b3a764000088615e76565b610e4e9190615e62565b11155b610e6d5760405162461bcd60e51b815260040161086890615d8f565b6000876001811115610e8f57634e487b7160e01b600052602160045260246000fd5b1415610ea057610ea0868983613acf565b600c54610eb7906001600160a01b03163383613ba7565b610ec13382613bfd565b6014546001600160a01b031615610f37576014546040516302c7739b60e01b81526001600160a01b03909116906302c7739b90610f049033908590600401615c78565b600060405180830381600087803b158015610f1e57600080fd5b505af1158015610f32573d6000803e3d6000fd5b505050505b600080896001600160a01b031663ba5b79826040518163ffffffff1660e01b8152600401604080518083038186803b158015610f7257600080fd5b505afa158015610f86573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610faa91906158fa565b9092509050600060018a6001811115610fd357634e487b7160e01b600052602160045260246000fd5b14610fde5782610fe0565b815b600c546040519192507f1d6ff70c632edb1e6aba7fbc0148db68c8392e30f9dfaadae2543a2543757cf69161102c9133918f918f918f918b916001600160a01b03909116908990615b9b565b60405180910390a15050505060045481146110595760405162461bcd60e51b815260040161086890615d58565b50505050505050565b61106d60083361314e565b6110895760405162461bcd60e51b815260040161086890615cc4565b600c546110a0906001600160a01b03168383613ba7565b5050565b6001600460008282546110b79190615e1c565b909155505060045460035460ff16156110e25760405162461bcd60e51b815260040161086890615cfb565b83158015906110f057508184145b6111535760405162461bcd60e51b815260206004820152602e60248201527f426f746820617272617973206861766520746f206265206e6f6e2d656d70747960448201526d20616e642073616d652073697a6560901b6064820152608401610868565b60005b84811015611254576111cb86868381811061118157634e487b7160e01b600052603260045260246000fd5b90506020020160208101906111969190615624565b8585848181106111b657634e487b7160e01b600052603260045260246000fd5b905060200201602081019061074b9190615624565b15611242576112428686838181106111f357634e487b7160e01b600052603260045260246000fd5b90506020020160208101906112089190615624565b85858481811061122857634e487b7160e01b600052603260045260246000fd5b905060200201602081019061123d9190615624565b613dc2565b8061124c81615ed8565b915050611156565b5060045481146112765760405162461bcd60e51b815260040161086890615d58565b5050505050565b6001600460008282546112909190615e1c565b909155505060045460035460ff16156112bb5760405162461bcd60e51b815260040161086890615cfb565b6001600160a01b038216156113305760165460405163bbddaca360e01b81526001600160a01b0384811660048301523360248301529091169063bbddaca390604401600060405180830381600087803b15801561131757600080fd5b505af115801561132b573d6000803e3d6000fd5b505050505b600061133b846140bf565b9050600081600f0b1380156113595750601b54600160a01b900460ff165b61138b5760405162461bcd60e51b815260206004820152600360248201526249443160e81b6044820152606401610868565b60008061139a8b8b8b896128ba565b60195491935091506000906001600160a01b03888116911614806113cb5750601a546001600160a01b038881169116145b6113d557826113e4565b6113e48364e8d4a51000615e76565b90506000601c5411801561142a5750670de0b6b3a7640000601c54670de0b6b3a76400006114129190615e95565b61141c9084615e76565b6114269190615e62565b8110155b61145c5760405162461bcd60e51b815260206004820152600360248201526249443360e81b6044820152606401610868565b61146e88670de0b6b3a7640000615e1c565b89611481670de0b6b3a764000086615e76565b61148b9190615e62565b11156114a95760405162461bcd60e51b815260040161086890615d8f565b6114be6001600160a01b038816333086614124565b601854604051635320bf6b60e11b8152600f86900b60048201526000602482015260448101859052606481018490526001600160a01b039091169063a6417ed690608401602060405180830381600087803b15801561151c57600080fd5b505af1158015611530573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115549190615b13565b506115648c8c8c858c600061415c565b50505050600454811461098f5760405162461bcd60e51b815260040161086890615d58565b600080600560019054906101000a90046001600160a01b03166001600160a01b031663bf46c0b4856001600160a01b031663059692b26040518163ffffffff1660e01b815260040160206040518083038186803b1580156115e957600080fd5b505afa1580156115fd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116219190615640565b600186600181111561164357634e487b7160e01b600052602160045260246000fd5b1461164f576000611652565b60015b670de0b6b3a76400006040518463ffffffff1660e01b815260040161167993929190615c13565b60206040518083038186803b15801561169157600080fd5b505afa1580156116a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116c99190615b13565b90506000600560019054906101000a90046001600160a01b03166001600160a01b031663bf46c0b4866001600160a01b03166392902ea96040518163ffffffff1660e01b815260040160206040518083038186803b15801561172a57600080fd5b505afa15801561173e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117629190615640565b600187600181111561178457634e487b7160e01b600052602160045260246000fd5b14611790576001611793565b60005b670de0b6b3a76400006040518463ffffffff1660e01b81526004016117ba93929190615c13565b60206040518083038186803b1580156117d257600080fd5b505afa1580156117e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061180a9190615b13565b90506118168183615ddb565b9250600184600181111561183a57634e487b7160e01b600052602160045260246000fd5b141561184e5761184b600284615e34565b92505b505092915050565b6001546001600160a01b031633146118ce5760405162461bcd60e51b815260206004820152603560248201527f596f75206d757374206265206e6f6d696e61746564206265666f726520796f7560448201527402063616e20616363657074206f776e65727368697605c1b6064820152608401610868565b60005460015460408051620100009093046001600160a01b03908116845290911660208301527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c910160405180910390a1600180546000805462010000600160b01b0319166001600160a01b03831662010000021790556001600160a01b0319169055565b6001600460008282546119669190615e1c565b909155505060045460035460ff16156119915760405162461bcd60e51b815260040161086890615cfb565b61199b8383613dc2565b60045481146119bc5760405162461bcd60e51b815260040161086890615d58565b505050565b846119cd60088261314e565b6119e95760405162461bcd60e51b815260040161086890615cc4565b6001600460008282546119fc9190615e1c565b909155505060045460035460ff1615611a275760405162461bcd60e51b815260040161086890615cfb565b611a368787878787600161415c565b60045481146110595760405162461bcd60e51b815260040161086890615d58565b6000808085611a6760088261314e565b611a835760405162461bcd60e51b815260040161086890615cc4565b6001866001811115611aa557634e487b7160e01b600052602160045260246000fd5b14611aba57611ab5600286615e62565b611abc565b845b9450600560019054906101000a90046001600160a01b03166001600160a01b0316630f13aae8886001600160a01b031663059692b26040518163ffffffff1660e01b815260040160206040518083038186803b158015611b1b57600080fd5b505afa158015611b2f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b539190615640565b6001896001811115611b7557634e487b7160e01b600052602160045260246000fd5b14611b81576000611b84565b60015b886040518463ffffffff1660e01b8152600401611ba393929190615c13565b60206040518083038186803b158015611bbb57600080fd5b505afa158015611bcf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bf39190615b13565b9250600560019054906101000a90046001600160a01b03166001600160a01b0316630f13aae8886001600160a01b03166392902ea96040518163ffffffff1660e01b815260040160206040518083038186803b158015611c5257600080fd5b505afa158015611c66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c8a9190615640565b6001896001811115611cac57634e487b7160e01b600052602160045260246000fd5b14611cb8576001611cbb565b60005b886040518463ffffffff1660e01b8152600401611cda93929190615c13565b60206040518083038186803b158015611cf257600080fd5b505afa158015611d06573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d2a9190615b13565b9150611d38868685856147f0565b93505093509350939050565b6000808085611d5460088261314e565b611d705760405162461bcd60e51b815260040161086890615cc4565b6001866001811115611d9257634e487b7160e01b600052602160045260246000fd5b14611da757611da2600286615e62565b611da9565b845b9450600560019054906101000a90046001600160a01b03166001600160a01b031663270e13ef886001600160a01b031663059692b26040518163ffffffff1660e01b815260040160206040518083038186803b158015611e0857600080fd5b505afa158015611e1c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e409190615640565b6001896001811115611e6257634e487b7160e01b600052602160045260246000fd5b14611e6e576000611e71565b60015b886040518463ffffffff1660e01b8152600401611e9093929190615c13565b60206040518083038186803b158015611ea857600080fd5b505afa158015611ebc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ee09190615b13565b9250600560019054906101000a90046001600160a01b03166001600160a01b031663270e13ef886001600160a01b03166392902ea96040518163ffffffff1660e01b815260040160206040518083038186803b158015611f3f57600080fd5b505afa158015611f53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f779190615640565b6001896001811115611f9957634e487b7160e01b600052602160045260246000fd5b14611fa5576001611fa8565b60005b886040518463ffffffff1660e01b8152600401611fc793929190615c13565b60206040518083038186803b158015611fdf57600080fd5b505afa158015611ff3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120179190615b13565b9150611d388686858561493a565b8561203160088261314e565b61204d5760405162461bcd60e51b815260040161086890615cc4565b6001600460008282546120609190615e1c565b909155505060045460035460ff161561208b5760405162461bcd60e51b815260040161086890615cfb565b6001600160a01b038316156121005760165460405163bbddaca360e01b81526001600160a01b0385811660048301523360248301529091169063bbddaca390604401600060405180830381600087803b1580156120e757600080fd5b505af11580156120fb573d6000803e3d6000fd5b505050505b61210f8888888888600161415c565b600454811461098f5760405162461bcd60e51b815260040161086890615d58565b60005b818110156119bc57600083838381811061215d57634e487b7160e01b600052603260045260246000fd5b90506020020160208101906121729190615624565b905061217f60088261314e565b80156121f95750806001600160a01b0316633f6fa6556040518163ffffffff1660e01b815260040160206040518083038186803b1580156121bf57600080fd5b505afa1580156121d3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121f79190615894565b155b1561225257806001600160a01b0316632b9b55b36040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561223957600080fd5b505af115801561224d573d6000803e3d6000fd5b505050505b508061225d81615ed8565b915050612133565b61226d6130d4565b60058054610100600160a81b0319166101006001600160a01b0387811682029290921792839055600c5460405163095ea7b360e01b81529083169363095ea7b3936122c393909104169060001990600401615c78565b602060405180830381600087803b1580156122dd57600080fd5b505af11580156122f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123159190615894565b50601480546001600160a01b039485166001600160a01b031991821617909155601680549390941692169190911790915560175550565b60008261235a60088261314e565b6123765760405162461bcd60e51b815260040161086890615cc4565b6000600560019054906101000a90046001600160a01b03166001600160a01b031663c2783f92866001600160a01b031663059692b26040518163ffffffff1660e01b815260040160206040518083038186803b1580156123d557600080fd5b505afa1580156123e9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061240d9190615640565b600187600181111561242f57634e487b7160e01b600052602160045260246000fd5b1461243b57600061243e565b60015b6040518363ffffffff1660e01b815260040161245b929190615bed565b60206040518083038186803b15801561247357600080fd5b505afa158015612487573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124ab9190615b13565b90506000600560019054906101000a90046001600160a01b03166001600160a01b031663c2783f92876001600160a01b03166392902ea96040518163ffffffff1660e01b815260040160206040518083038186803b15801561250c57600080fd5b505afa158015612520573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125449190615640565b600188600181111561256657634e487b7160e01b600052602160045260246000fd5b14612572576001612575565b60005b6040518363ffffffff1660e01b8152600401612592929190615bed565b60206040518083038186803b1580156125aa57600080fd5b505afa1580156125be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125e29190615b13565b90508082106125f157806125f3565b815b9350600085600181111561261757634e487b7160e01b600052602160045260246000fd5b141561262b57612628846002615e76565b93505b50505092915050565b61263c6130d4565b6001600160a01b0381166126845760405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b6044820152606401610868565b600154600160a81b900460ff16156126d45760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481d1c985b9cd9995c9c9959606a1b6044820152606401610868565b600080546001600160a01b038381166201000081810262010000600160b01b031990941693909317938490556001805460ff60a81b1916600160a81b1790556040805193909404909116825260208201527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9101610b40565b6127556130d4565b601b8054921515600160a01b0260ff60a01b1990931692909217909155601c55565b61277f6130d4565b600f84905560108390556013829055601581905560408051858152602081018590527f791bda8941b9b34beac92ee11a95b4b8849671b4237e64bf2012e43d83f60b80910160405180910390a17f3f8ee248e54cbfb3fd6ac9e30faa707a797b66f46fe5bb641a0161bb9aa5394660135460155460405161280a929190918252602082015260400190565b60405180910390a150505050565b6128206130d4565b6012829055601180546001600160a01b0319166001600160a01b0385169081179091556040805184815260208101929092527fb35f856d2e2560c924ec77d0d16cc4dd4294fea9e5cf024191f7af55cab7a52f910160405180910390a160068190556040518181527fbd333e349147c420e7c1cd97321f3ec84bb6912b70c6d0437fac423c0649cb4b9060200160405180910390a1505050565b60008060006128c8846140bf565b9050600081600f0b1380156128e65750601b54600160a01b900460ff165b156129c9576128f6878787610c17565b9150670de0b6b3a76400006129136005662386f26fc10000615e62565b61292590670de0b6b3a7640000615e1c565b6018546040516307211ef760e01b815260006004820152600f85900b6024820152604481018690526001600160a01b03909116906307211ef79060640160206040518083038186803b15801561297a57600080fd5b505afa15801561298e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129b29190615b13565b6129bc9190615e76565b6129c69190615e62565b92505b5094509492505050565b600554604051635727a0f360e01b81526001600160a01b03848116600483015260009261010090041690635727a0f39060240160206040518083038186803b158015612a1e57600080fd5b505afa158015612a32573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a569190615894565b8015612ae05750600554604051635727a0f360e01b81526001600160a01b03848116600483015261010090920490911690635727a0f39060240160206040518083038186803b158015612aa857600080fd5b505afa158015612abc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ae09190615894565b15612dba576000836001600160a01b0316639e3b34bf6040518163ffffffff1660e01b8152600401604080518083038186803b158015612b1f57600080fd5b505afa158015612b33573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b579190615b2b565b5090506000836001600160a01b0316639e3b34bf6040518163ffffffff1660e01b8152600401604080518083038186803b158015612b9457600080fd5b505afa158015612ba8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bcc9190615b2b565b509050600080866001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b158015612c0b57600080fd5b505afa158015612c1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c4391906158cd565b5091509150600080876001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b158015612c8457600080fd5b505afa158015612c98573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cbc91906158cd565b50915091508184148015612ccf57508083105b8015612cda57508486145b15612db35780670de0b6b3a764000084662386f26fc10000601354612cff9190615e76565b612d1190670de0b6b3a7640000615e1c565b612d1b9190615e76565b612d259190615e62565b10612d335760009650612db3565b80670de0b6b3a764000084662386f26fc10000601554612d539190615e76565b612d6590670de0b6b3a7640000615e1c565b612d6f9190615e76565b612d799190615e62565b11612d875760009650612db3565b6001600160a01b0389811660009081526007602090815260408083208c85168452909152902054161596505b5050505050505b92915050565b60055460ff1615612e095760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b6044820152606401610868565b6005805460ff19166001908117909155600455565b6110896130d4565b600082612e3460088261314e565b612e505760405162461bcd60e51b815260040161086890615cc4565b6000600560019054906101000a90046001600160a01b03166001600160a01b031663efc15251866001600160a01b031663059692b26040518163ffffffff1660e01b815260040160206040518083038186803b158015612eaf57600080fd5b505afa158015612ec3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ee79190615640565b6001876001811115612f0957634e487b7160e01b600052602160045260246000fd5b14612f15576000612f18565b60015b6040518363ffffffff1660e01b8152600401612f35929190615bed565b60206040518083038186803b158015612f4d57600080fd5b505afa158015612f61573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f859190615b13565b90506000600560019054906101000a90046001600160a01b03166001600160a01b031663efc15251876001600160a01b03166392902ea96040518163ffffffff1660e01b815260040160206040518083038186803b158015612fe657600080fd5b505afa158015612ffa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061301e9190615640565b600188600181111561304057634e487b7160e01b600052602160045260246000fd5b1461304c57600161304f565b60005b6040518363ffffffff1660e01b815260040161306c929190615bed565b60206040518083038186803b15801561308457600080fd5b505afa158015613098573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130bc9190615b13565b90508082106130cb5780612628565b50949350505050565b6000546201000090046001600160a01b0316331461314c5760405162461bcd60e51b815260206004820152602f60248201527f4f6e6c792074686520636f6e7472616374206f776e6572206d6179207065726660448201526e37b936903a3434b99030b1ba34b7b760891b6064820152608401610868565b565b815460009061315f57506000612dba565b6001600160a01b0382166000908152600184016020526040902054801515806131c85750826001600160a01b0316846000016000815481106131b157634e487b7160e01b600052603260045260246000fd5b6000918252602090912001546001600160a01b0316145b949350505050565b6000816132df57600560019054906101000a90046001600160a01b03166001600160a01b031663481c6a756040518163ffffffff1660e01b815260040160206040518083038186803b15801561322557600080fd5b505afa158015613239573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061325d9190615640565b6001600160a01b031663edc892e1846040518263ffffffff1660e01b815260040161328a91815260200190565b60206040518083038186803b1580156132a257600080fd5b505afa1580156132b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132da9190615b13565b6133e2565b600560019054906101000a90046001600160a01b03166001600160a01b031663481c6a756040518163ffffffff1660e01b815260040160206040518083038186803b15801561332d57600080fd5b505afa158015613341573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133659190615640565b6001600160a01b03166317fd849a846040518263ffffffff1660e01b815260040161339291815260200190565b60206040518083038186803b1580156133aa57600080fd5b505afa1580156133be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133e29190615b13565b9392505050565b600080826001600160a01b031663059692b26040518163ffffffff1660e01b815260040160206040518083038186803b15801561342557600080fd5b505afa158015613439573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061345d9190615640565b6001600160a01b031663cc2ee1966040518163ffffffff1660e01b8152600401604080518083038186803b15801561349457600080fd5b505afa1580156134a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134cc91906158fa565b91509150600080846001600160a01b03166392902ea96040518163ffffffff1660e01b815260040160206040518083038186803b15801561350c57600080fd5b505afa158015613520573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135449190615640565b6001600160a01b031663cc2ee1966040518163ffffffff1660e01b8152600401604080518083038186803b15801561357b57600080fd5b505afa15801561358f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135b391906158fa565b60055460405163095ea7b360e01b81529294509092506001600160a01b038087169263095ea7b3926135f392610100909104169060001990600401615c78565b602060405180830381600087803b15801561360d57600080fd5b505af1158015613621573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136459190615894565b5060055460405163095ea7b360e01b81526001600160a01b038086169263095ea7b392613682926101009092049091169060001990600401615c78565b602060405180830381600087803b15801561369c57600080fd5b505af11580156136b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136d49190615894565b5060055460405163095ea7b360e01b81526001600160a01b038085169263095ea7b392613711926101009092049091169060001990600401615c78565b602060405180830381600087803b15801561372b57600080fd5b505af115801561373f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137639190615894565b5060055460405163095ea7b360e01b81526001600160a01b038084169263095ea7b3926137a0926101009092049091169060001990600401615c78565b602060405180830381600087803b1580156137ba57600080fd5b505af11580156137ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137f29190615894565b505050505050565b600080600184600181111561381f57634e487b7160e01b600052602160045260246000fd5b146138345761382f600284615e62565b613836565b825b90506000600560019054906101000a90046001600160a01b03166001600160a01b0316633ce1108d876001600160a01b031663059692b26040518163ffffffff1660e01b815260040160206040518083038186803b15801561389757600080fd5b505afa1580156138ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138cf9190615640565b60018860018111156138f157634e487b7160e01b600052602160045260246000fd5b146138fd576000613900565b60015b856000806040518663ffffffff1660e01b8152600401613924959493929190615c3d565b602060405180830381600087803b15801561393e57600080fd5b505af1158015613952573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139769190615b13565b90506000600560019054906101000a90046001600160a01b03166001600160a01b0316633ce1108d886001600160a01b03166392902ea96040518163ffffffff1660e01b815260040160206040518083038186803b1580156139d757600080fd5b505afa1580156139eb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a0f9190615640565b6001896001811115613a3157634e487b7160e01b600052602160045260246000fd5b14613a3d576001613a40565b60005b866000806040518663ffffffff1660e01b8152600401613a64959493929190615c3d565b602060405180830381600087803b158015613a7e57600080fd5b505af1158015613a92573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ab69190615b13565b9050613ac4868484846147f0565b979650505050505050565b60125460009015613ba15781601254670de0b6b3a7640000613af19190615e95565b613b03670de0b6b3a764000085615e76565b613b0d9190615e62565b613b179190615e95565b600c5460115460405163a9059cbb60e01b81529293506001600160a01b039182169263a9059cbb92613b4f9216908590600401615c78565b602060405180830381600087803b158015613b6957600080fd5b505af1158015613b7d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112769190615894565b50505050565b6119bc8363a9059cbb60e01b8484604051602401613bc6929190615c78565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614a56565b6000601754118015613c1957506016546001600160a01b031615155b156110a057601654604051639ca423b360e01b81526001600160a01b0384811660048301526000921690639ca423b39060240160206040518083038186803b158015613c6457600080fd5b505afa158015613c78573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c9c9190615640565b90506001600160a01b038116156119bc57600082670de0b6b3a7640000601754670de0b6b3a7640000613ccf9190615e1c565b613cd99086615e76565b613ce39190615e62565b613ced9190615e95565b600c5460405163a9059cbb60e01b81529192506001600160a01b03169063a9059cbb90613d209085908590600401615c78565b602060405180830381600087803b158015613d3a57600080fd5b505af1158015613d4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d729190615894565b50604080516001600160a01b03808516825286166020820152908101829052606081018490527f8fa68a6a8e2fc9ff758a6e64afba8bc2f66fb082999a2c5225c8c49633faded49060800161280a565b613dcc82826129d3565b613e235760405162461bcd60e51b815260206004820152602260248201527f43616e277420637265617465207375636820612072616e676564206d61726b65604482015261742160f01b6064820152608401610868565b600a54600090613e3b906001600160a01b0316614b28565b6001600160a01b0384811660009081526007602090815260408083208785168452909152812080546001600160a01b031916848416179055600b5492935091613e849116614b28565b60405163613d25bb60e01b81526001600160a01b03848116600483015260806024830152600b60848301526a2837b9b4ba34b7b71024a760a91b60a483015260c06044830152600260c48301526124a760f11b60e48301523060648301529192509082169063613d25bb9061010401600060405180830381600087803b158015613f0d57600080fd5b505af1158015613f21573d6000803e3d6000fd5b5050600b5460009250613f3d91506001600160a01b0316614b28565b60405163613d25bb60e01b81526001600160a01b03858116600483015260806024830152600c60848301526b141bdcda5d1a5bdb8813d55560a21b60a483015260c06044830152600360c48301526213d55560ea1b60e48301523060648301529192509082169063613d25bb9061010401600060405180830381600087803b158015613fc857600080fd5b505af1158015613fdc573d6000803e3d6000fd5b5050604051630a2ca2bd60e11b81526001600160a01b03888116600483015287811660248301528581166044830152848116606483015230608483015286169250631459457a915060a401600060405180830381600087803b15801561404157600080fd5b505af1158015614055573d6000803e3d6000fd5b5050505061406d836008614bc590919063ffffffff16565b604080516001600160a01b038581168252878116602083015286168183015290517f0f336b6e697d4fa9ca222d3db749b9bdd3b8a7fbe9029ee98c0081aa69dfb4139181900360600190a15050505050565b601b546000906001600160a01b03838116911614156140e057506001919050565b6019546001600160a01b03838116911614156140fe57506002919050565b601a546001600160a01b038381169116141561411c57506003919050565b506000919050565b6040516001600160a01b0380851660248301528316604482015260648101829052613ba19085906323b872dd60e01b90608401613bc6565b836141678787612e26565b101561419b5760405162461bcd60e51b815260206004820152600360248201526212510d60ea1b6044820152606401610868565b600080600080896001600160a01b031663ba5b79826040518163ffffffff1660e01b8152600401604080518083038186803b1580156141d957600080fd5b505afa1580156141ed573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061421191906158fa565b9092509050600189600181111561423857634e487b7160e01b600052602160045260246000fd5b14156142525780925061424b8a89614c17565b935061426c565b81925061425f8a8961503e565b935061426c8a898661548a565b600061428489610c6a670de0b6b3a764000088615e76565b9050600f548111801561429e5750670de0b6b3a764000081105b6142d05760405162461bcd60e51b815260206004820152600360248201526249443560e81b6044820152606401610868565b60008511801561430d57506142ed87670de0b6b3a7640000615e1c565b88614300670de0b6b3a764000088615e76565b61430a9190615e62565b11155b6143295760405162461bcd60e51b815260040161086890615d8f565b851561434757600c54614347906001600160a01b0316333088614124565b60405163200cd24760e21b81526001600160a01b038c1690638033491c90614377908c908e903390600401615dac565b600060405180830381600087803b15801561439157600080fd5b505af11580156143a5573d6000803e3d6000fd5b505050506143b33386613bfd565b6014546001600160a01b031615614429576014546040516302c7739b60e01b81526001600160a01b03909116906302c7739b906143f69033908990600401615c78565b600060405180830381600087803b15801561441057600080fd5b505af1158015614424573d6000803e3d6000fd5b505050505b600c546040517ff3bfbc0822d1ed667a2b298e71e0304f2c1f4685398189d7c39e412f733150f4916144709133918f918f918f918c916001600160a01b0316908c90615b9b565b60405180910390a16000808c6001600160a01b031663059692b26040518163ffffffff1660e01b815260040160206040518083038186803b1580156144b457600080fd5b505afa1580156144c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144ec9190615640565b6001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b15801561452457600080fd5b505afa158015614538573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061455c91906158cd565b509150915060008d6001600160a01b03166392902ea96040518163ffffffff1660e01b815260040160206040518083038186803b15801561459c57600080fd5b505afa1580156145b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145d49190615640565b6001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b15801561460c57600080fd5b505afa158015614620573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061464491906158cd565b509150506000600560019054906101000a90046001600160a01b03166001600160a01b031663741bef1a6040518163ffffffff1660e01b815260040160206040518083038186803b15801561469857600080fd5b505afa1580156146ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146d09190615640565b6001600160a01b031663ac82f608856040518263ffffffff1660e01b81526004016146fd91815260200190565b60206040518083038186803b15801561471557600080fd5b505afa158015614729573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061474d9190615b13565b90506000808f600181111561477257634e487b7160e01b600052602160045260246000fd5b1461478a57838210806147855750828210155b614799565b83821015801561479957508282105b60408051338152602081018d90528215158183015290519192507f80631c28c8a8100630a9d2bce38b276a55426b59f4d47fb06072105118083ec1919081900360600190a150505050505050505050505050505050565b600080831180156148015750600082115b156131c85760006148128385615e1c565b9050600186600181111561483657634e487b7160e01b600052602160045260246000fd5b141561487657670de0b6b3a7640000600654670de0b6b3a764000061485b9190615e95565b6148659083615e76565b61486f9190615e62565b91506130cb565b60006148838660006131d0565b9050848111801561489357508381115b80156148bb57506148a48482615e95565b6148ae8683615e95565b6148b89190615e1c565b82115b156149305760006148cc8583615e95565b6148d68784615e95565b6148e09190615e1c565b6148ea9084615e95565b9050670de0b6b3a7640000601254600654670de0b6b3a764000061490e9190615e95565b6149189190615e95565b6149229083615e76565b61492c9190615e62565b9350505b5050949350505050565b6000808311801561494b5750600082115b156131c857600061495c8385615e1c565b9050600186600181111561498057634e487b7160e01b600052602160045260246000fd5b141561499d57670de0b6b3a76400008060065461485b9190615e1c565b826149a98660006131d0565b6149b39190615e95565b846149bf8760006131d0565b6149c99190615e95565b6149d39190615e1c565b8111156130cb576000836149e88760006131d0565b6149f29190615e95565b856149fe8860006131d0565b614a089190615e95565b614a129084615e95565b614a1c9190615e95565b9050670de0b6b3a764000080601254600654614a389190615e1c565b614a429190615e1c565b614a4c9083615e76565b613ac49190615e62565b6000614aab826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166154d09092919063ffffffff16565b8051909150156119bc5780806020019051810190614ac99190615894565b6119bc5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610868565b6000604051733d602d80600a3d3981f3363d3d373d3d3d363d7360601b81528260601b60148201526e5af43d82803e903d91602b57fd5bf360881b60288201526037816000f09150506001600160a01b038116614bc05760405162461bcd60e51b8152602060048201526016602482015275115490cc4c4d8dce8818dc99585d194819985a5b195960521b6044820152606401610868565b919050565b614bcf828261314e565b6110a05781546001600160a01b038216600081815260018086016020908152604083208590559084018655858252902090910180546001600160a01b03191690911790555050565b600080600560019054906101000a90046001600160a01b03166001600160a01b0316638875eb84856001600160a01b031663059692b26040518163ffffffff1660e01b815260040160206040518083038186803b158015614c7757600080fd5b505afa158015614c8b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614caf9190615640565b60018660001960006040518663ffffffff1660e01b8152600401614cd7959493929190615c3d565b602060405180830381600087803b158015614cf157600080fd5b505af1158015614d05573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614d299190615b13565b90506000600560019054906101000a90046001600160a01b03166001600160a01b0316638875eb84866001600160a01b03166392902ea96040518163ffffffff1660e01b815260040160206040518083038186803b158015614d8a57600080fd5b505afa158015614d9e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614dc29190615640565b60008760001960006040518663ffffffff1660e01b8152600401614dea959493929190615c3d565b602060405180830381600087803b158015614e0457600080fd5b505af1158015614e18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614e3c9190615b13565b90506000856001600160a01b031663059692b26040518163ffffffff1660e01b815260040160206040518083038186803b158015614e7957600080fd5b505afa158015614e8d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614eb19190615640565b6001600160a01b031663cc2ee1966040518163ffffffff1660e01b8152600401604080518083038186803b158015614ee857600080fd5b505afa158015614efc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614f2091906158fa565b9150614f3890506001600160a01b0382168787613ba7565b6000866001600160a01b03166392902ea96040518163ffffffff1660e01b815260040160206040518083038186803b158015614f7357600080fd5b505afa158015614f87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614fab9190615640565b6001600160a01b031663cc2ee1966040518163ffffffff1660e01b8152600401604080518083038186803b158015614fe257600080fd5b505afa158015614ff6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061501a91906158fa565b5090506150316001600160a01b0382168888613ba7565b613ac4600187868661493a565b600080600560019054906101000a90046001600160a01b03166001600160a01b0316638875eb84856001600160a01b031663059692b26040518163ffffffff1660e01b815260040160206040518083038186803b15801561509e57600080fd5b505afa1580156150b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906150d69190615640565b60006150e3600288615e62565b60001960006040518663ffffffff1660e01b8152600401615108959493929190615c3d565b602060405180830381600087803b15801561512257600080fd5b505af1158015615136573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061515a9190615b13565b90506000600560019054906101000a90046001600160a01b03166001600160a01b0316638875eb84866001600160a01b03166392902ea96040518163ffffffff1660e01b815260040160206040518083038186803b1580156151bb57600080fd5b505afa1580156151cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906151f39190615640565b6001615200600289615e62565b60001960006040518663ffffffff1660e01b8152600401615225959493929190615c3d565b602060405180830381600087803b15801561523f57600080fd5b505af1158015615253573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906152779190615b13565b90506000856001600160a01b031663059692b26040518163ffffffff1660e01b815260040160206040518083038186803b1580156152b457600080fd5b505afa1580156152c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906152ec9190615640565b6001600160a01b031663cc2ee1966040518163ffffffff1660e01b8152600401604080518083038186803b15801561532357600080fd5b505afa158015615337573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061535b91906158fa565b50905061537e8661536d600288615e62565b6001600160a01b0384169190613ba7565b6000866001600160a01b03166392902ea96040518163ffffffff1660e01b815260040160206040518083038186803b1580156153b957600080fd5b505afa1580156153cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906153f19190615640565b6001600160a01b031663cc2ee1966040518163ffffffff1660e01b8152600401604080518083038186803b15801561542857600080fd5b505afa15801561543c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061546091906158fa565b915061547390508761536d600289615e62565b613ac46000615483600289615e62565b868661493a565b60125460009015613ba1576012546154aa90670de0b6b3a7640000615e1c565b6154bc670de0b6b3a764000084615e76565b6154c69190615e62565b613b179083615e95565b60606131c8848460008585843b6155295760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610868565b600080866001600160a01b031685876040516155459190615b7f565b60006040518083038185875af1925050503d8060008114615582576040519150601f19603f3d011682016040523d82523d6000602084013e615587565b606091505b5091509150613ac4828286606083156155a15750816133e2565b8251156155b15782518084602001fd5b8160405162461bcd60e51b81526004016108689190615c91565b60008083601f8401126155dc578182fd5b50813567ffffffffffffffff8111156155f3578182fd5b6020830191508360208260051b850101111561560e57600080fd5b9250929050565b803560028110614bc057600080fd5b600060208284031215615635578081fd5b81356133e281615f3d565b600060208284031215615651578081fd5b81516133e281615f3d565b6000806040838503121561566e578081fd5b823561567981615f3d565b946020939093013593505050565b60008060408385031215615699578182fd5b82356156a481615f3d565b915060208301356156b481615f3d565b809150509250929050565b600080600080608085870312156156d4578182fd5b84356156df81615f3d565b935060208501356156ef81615f3d565b925060408501356156ff81615f3d565b9396929550929360600135925050565b600080600080600080600060e0888a031215615729578283fd5b873561573481615f3d565b9650602088013561574481615f3d565b95506040880135945060608801359350608088013561576281615f3d565b925060a088013561577281615f3d565b8092505060c0880135905092959891949750929550565b6000806040838503121561566e578182fd5b6000806000606084860312156157af578081fd5b83356157ba81615f3d565b95602085013595506040909401359392505050565b600080602083850312156157e1578182fd5b823567ffffffffffffffff8111156157f7578283fd5b615803858286016155cb565b90969095509350505050565b60008060008060408587031215615824578182fd5b843567ffffffffffffffff8082111561583b578384fd5b615847888389016155cb565b9096509450602087013591508082111561585f578384fd5b5061586c878288016155cb565b95989497509550505050565b600060208284031215615889578081fd5b81356133e281615f52565b6000602082840312156158a5578081fd5b81516133e281615f52565b600080604083850312156158c2578182fd5b823561567981615f52565b6000806000606084860312156158e1578081fd5b8351925060208401519150604084015190509250925092565b6000806040838503121561590c578182fd5b825161591781615f3d565b60208401519092506156b481615f3d565b6000806040838503121561593a578182fd5b823561594581615f3d565b915061595360208401615615565b90509250929050565b600080600060608486031215615970578081fd5b833561597b81615f3d565b925061598960208501615615565b9150604084013590509250925092565b600080600080608085870312156159ae578182fd5b84356159b981615f3d565b93506159c760208601615615565b92506040850135915060608501356159de81615f3d565b939692955090935050565b600080600080600060a08688031215615a00578283fd5b8535615a0b81615f3d565b9450615a1960208701615615565b94979496505050506040830135926060810135926080909101359150565b60008060008060008060c08789031215615a4f578384fd5b8635615a5a81615f3d565b9550615a6860208801615615565b945060408701359350606087013592506080870135915060a0870135615a8d81615f3d565b809150509295509295509295565b600080600080600080600060e0888a031215615ab5578081fd5b8735615ac081615f3d565b9650615ace60208901615615565b955060408801359450606088013593506080880135925060a0880135615af381615f3d565b915060c0880135615b0381615f3d565b8091505092959891949750929550565b600060208284031215615b24578081fd5b5051919050565b60008060408385031215615b3d578182fd5b505080516020909101519092909150565b60008060008060808587031215615b63578182fd5b5050823594602084013594506040840135936060013592509050565b60008251615b91818460208701615eac565b9190910192915050565b6001600160a01b038881168252878116602083015260e0820190615bbe88615f1f565b87604084015286606084015285608084015280851660a084015280841660c08401525098975050505050505050565b6001600160a01b038316815260408101615c0683615f1f565b8260208301529392505050565b6001600160a01b038416815260608101615c2c84615f1f565b602082019390935260400152919050565b6001600160a01b038616815260a08101615c5686615f1f565b8560208301528460408301528360608301528260808301529695505050505050565b6001600160a01b03929092168252602082015260400190565b6020815260008251806020840152615cb0816040850160208701615eac565b601f01601f19169190910160400192915050565b60208082526019908201527f4e6f742061206b6e6f776e2072616e676564206d61726b657400000000000000604082015260600190565b6020808252603c908201527f5468697320616374696f6e2063616e6e6f7420626520706572666f726d65642060408201527f7768696c652074686520636f6e74726163742069732070617573656400000000606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60208082526003908201526224a21960e91b604082015260600190565b83815260608101615dbc84615f1f565b60208201939093526001600160a01b0391909116604090910152919050565b600080821280156001600160ff1b0384900385131615615dfd57615dfd615ef3565b600160ff1b8390038412811615615e1657615e16615ef3565b50500190565b60008219821115615e2f57615e2f615ef3565b500190565b600082615e4357615e43615f09565b600160ff1b821460001984141615615e5d57615e5d615ef3565b500590565b600082615e7157615e71615f09565b500490565b6000816000190483118215151615615e9057615e90615ef3565b500290565b600082821015615ea757615ea7615ef3565b500390565b60005b83811015615ec7578181015183820152602001615eaf565b83811115613ba15750506000910152565b6000600019821415615eec57615eec615ef3565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b60028110610c1457634e487b7160e01b600052602160045260246000fd5b6001600160a01b0381168114610c1457600080fd5b8015158114610c1457600080fdfea2646970667358221220cca7533b72479b4e64d8d8ca4c1b63f9c328313b65975adbd7a3d07cc971c54f64736f6c63430008040033

Block Transaction Difficulty Gas Used Reward
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.