Contract Overview
Balance:
0 ETH
EtherValue:
$0.00
My Name Tag:
Not Available, login to update
Txn Hash | Method |
Block
|
From
|
To
|
Value | ||||
---|---|---|---|---|---|---|---|---|---|
0xed616c7c9286c29dbcc975e6ad1b6aa97b8f39ffa5135c8b1f44858bc67f1e28 | 0x60806040 | 3997518 | 15 days 2 hrs ago | 0x625796b2869d94de2d11841288789663005c080f | IN | Create: SportsAMM | 0 ETH | 0.009179989582 |
[ Download CSV Export ]
Contract Name:
SportsAMM
Compiler Version
v0.8.4+commit.c7e474f2
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; // internal import "../utils/proxy/solidity-0.8.0/ProxyReentrancyGuard.sol"; import "../utils/proxy/solidity-0.8.0/ProxyOwned.sol"; // interface import "../interfaces/ISportPositionalMarket.sol"; import "../interfaces/ISportPositionalMarketManager.sol"; import "../interfaces/IPosition.sol"; import "../interfaces/IStakingThales.sol"; import "../interfaces/ITherundownConsumer.sol"; import "../interfaces/ICurveSUSD.sol"; import "../interfaces/IReferrals.sol"; import "../interfaces/ISportsAMM.sol"; import "../interfaces/ITherundownConsumerWrapper.sol"; import "../interfaces/ISportAMMRiskManager.sol"; import "./SportsAMMUtils.sol"; import "./LiquidityPool/SportAMMLiquidityPool.sol"; /// @title Sports AMM contract /// @author kirilaa contract SportsAMM is Initializable, ProxyOwned, PausableUpgradeable, ProxyReentrancyGuard { using SafeERC20Upgradeable for IERC20Upgradeable; uint private constant ONE = 1e18; uint private constant ZERO_POINT_ONE = 1e17; uint private constant ONE_PERCENT = 1e16; uint private constant MAX_APPROVAL = type(uint256).max; uint public constant TAG_NUMBER_PLAYERS = 10010; /// @return The sUSD contract used for payment IERC20Upgradeable public sUSD; /// @return The address of the SportsPositionalManager contract address public manager; /// @notice Each game has `defaultCapPerGame` available for trading /// @return The default cap per game. uint public defaultCapPerGame; //deprecated see SportAMMRiskManager.sol /// @return The minimal spread/skrew percentage uint public min_spread; /// @return The maximum spread/skrew percentage uint public max_spread; /// @notice Each game will be restricted for AMM trading `minimalTimeLeftToMaturity` seconds before is mature /// @return The period of time before a game is matured and begins to be restricted for AMM trading uint public minimalTimeLeftToMaturity; enum Position { Home, Away, Draw } /// @return The sUSD amount bought from AMM by users for the market mapping(address => uint) public spentOnGame; /// @return The SafeBox address address public safeBox; /// @return The address of Therundown Consumer address public theRundownConsumer; /// @return The percentage that goes to SafeBox uint public safeBoxImpact; /// @return The address of the Staking contract IStakingThales public stakingThales; /// @return The minimum supported odd uint public minSupportedOdds; /// @return The maximum supported odd uint public maxSupportedOdds; /// @return The address of the Curve contract for multi-collateral ICurveSUSD public curveSUSD; /// @return The address of USDC address public usdc; /// @return The address of USDT (Tether) address public usdt; /// @return The address of DAI address public dai; /// @return Curve usage is enabled? bool public curveOnrampEnabled; /// @return Referrals contract address address public referrals; /// @return Default referrer fee uint public referrerFee; /// @return The address of Parlay AMM address public parlayAMM; /// @return The address of Apex Consumer address public apexConsumer; // deprecated /// @return maximum supported discount in percentage on sUSD purchases with different collaterals uint public maxAllowedPegSlippagePercentage; /// @return the cap per sportID. based on the tagID mapping(uint => uint) public capPerSport; //deprecated see SportAMMRiskManager.sol SportsAMMUtils public sportAmmUtils; /// @return the cap per market. based on the marketId mapping(address => uint) public capPerMarket; //deprecated see SportAMMRiskManager.sol /// @notice odds threshold which will trigger odds update /// @return The threshold. uint public thresholdForOddsUpdate; /// @return The address of wrapper contract ITherundownConsumerWrapper public wrapper; // @return specific SafeBoxFee per address mapping(address => uint) public safeBoxFeePerAddress; // @return specific min_spread per address mapping(address => uint) public min_spreadPerAddress; /// @return the cap per sportID and childID. based on the tagID[0] and tagID[1] mapping(uint => mapping(uint => uint)) public capPerSportAndChild; //deprecated see SportAMMRiskManager.sol struct BuyFromAMMParams { address market; ISportsAMM.Position position; uint amount; uint expectedPayout; uint additionalSlippage; bool sendSUSD; uint sUSDPaid; } struct DoubleChanceStruct { bool isDoubleChance; ISportsAMM.Position position1; ISportsAMM.Position position2; address parentMarket; } /// @return the adddress of the AMMLP contract SportAMMLiquidityPool public liquidityPool; // @return specific min_spread per address mapping(uint => mapping(uint => uint)) public minSpreadPerSport; /// @return the sport which is one-sider mapping(uint => bool) public isMarketForSportOnePositional; //deprecated see SportAMMRiskManager.sol /// @return The maximum supported odd for sport mapping(uint => uint) public minSupportedOddsPerSport; /// @return The maximum supported odd for sport mapping(uint => uint) public maxSpreadPerSport; ISportAMMRiskManager public riskManager; /// @return The sUSD amount bought from AMM by users for the parent mapping(address => uint) public spentOnParent; /// @notice Initialize the storage in the proxy contract with the parameters. /// @param _owner Owner for using the ownerOnly functions /// @param _sUSD The payment token (sUSD) /// @param _min_spread Minimal spread (percentage) /// @param _max_spread Maximum spread (percentage) /// @param _minimalTimeLeftToMaturity Period to close AMM trading befor maturity function initialize( address _owner, IERC20Upgradeable _sUSD, uint _min_spread, uint _max_spread, uint _minimalTimeLeftToMaturity ) public initializer { setOwner(_owner); initNonReentrant(); sUSD = _sUSD; min_spread = _min_spread; max_spread = _max_spread; minimalTimeLeftToMaturity = _minimalTimeLeftToMaturity; } /// @notice Returns the available position options to buy from AMM for specific market/game /// @param market The address of the SportPositional market created for a game /// @param position The position (home/away/draw) to check availability /// @return _available The amount of position options (tokens) available to buy from AMM. function availableToBuyFromAMM(address market, ISportsAMM.Position position) public view returns (uint _available) { if (isMarketInAMMTrading(market)) { uint baseOdds = _obtainOdds(market, position); if (baseOdds > 0) { _available = _availableToBuyFromAMMInternal( market, position, baseOdds, 0, false, _getDoubleChanceStruct(market) ); } } } /// @notice Calculate the sUSD cost to buy an amount of available position options from AMM for specific market/game /// @param market The address of the SportPositional market of a game /// @param position The position (home/away/draw) quoted to buy from AMM /// @param amount The position amount quoted to buy from AMM /// @return _quote The sUSD cost for buying the `amount` of `position` options (tokens) from AMM for `market`. function buyFromAmmQuote( address market, ISportsAMM.Position position, uint amount ) public view returns (uint _quote) { if (isMarketInAMMTrading(market)) { uint baseOdds = _obtainOdds(market, position); if (baseOdds > 0) { uint minOdds = _minOddsForMarket(market); baseOdds = baseOdds < minOdds ? minOdds : baseOdds; _quote = _buyFromAmmQuoteWithBaseOdds( market, position, amount, baseOdds, safeBoxImpact, 0, false, true, _getDoubleChanceStruct(market) ); } } } function _buyFromAmmQuoteWithBaseOdds( address market, ISportsAMM.Position position, uint amount, uint baseOdds, uint useSafeBoxSkewImpact, uint available, bool useAvailable, bool useDefaultMinSpread, DoubleChanceStruct memory dcs ) internal view returns (uint returnQuote) { if (dcs.isDoubleChance) { returnQuote = _buyFromAMMQuoteDoubleChance( market, position, amount, useSafeBoxSkewImpact, useDefaultMinSpread, dcs ); } else { returnQuote = _buyFromAmmQuoteWithBaseOddsInternal( market, position, amount, baseOdds, useSafeBoxSkewImpact, available, useAvailable, useDefaultMinSpread ); } } function _buyFromAmmQuoteWithBaseOddsInternal( address market, ISportsAMM.Position position, uint amount, uint baseOdds, uint useSafeBoxSkewImpact, uint available, bool useAvailable, bool useDefaultMinSpread ) internal view returns (uint returnQuote) { uint _available = useAvailable ? available : _availableToBuyFromAMMWithBaseOdds(market, position, baseOdds, 0, false); uint _availableOtherSide = _getAvailableOtherSide(market, position); if (amount <= _available) { int skewImpact = _buyPriceImpact(market, position, amount, _available, _availableOtherSide); baseOdds = (baseOdds * (ONE + _getMinSpreadToUse(useDefaultMinSpread, market))) / ONE; int tempQuote = sportAmmUtils.calculateTempQuote(skewImpact, baseOdds, useSafeBoxSkewImpact, amount); returnQuote = ISportPositionalMarketManager(manager).transformCollateral(uint(tempQuote)); } } function _getTagsForMarket(address _market) internal view returns (uint tag1, uint tag2) { ISportPositionalMarket sportMarket = ISportPositionalMarket(_market); tag1 = sportMarket.tags(0); tag2 = sportMarket.isChild() ? sportMarket.tags(1) : 0; } function _getMinSpreadToUse(bool useDefaultMinSpread, address market) internal view returns (uint min_spreadToUse) { (uint tag1, uint tag2) = _getTagsForMarket(market); uint spreadForTag = tag2 > 0 && minSpreadPerSport[tag1][tag2] > 0 ? minSpreadPerSport[tag1][tag2] : minSpreadPerSport[tag1][0]; min_spreadToUse = useDefaultMinSpread ? (spreadForTag > 0 ? spreadForTag : min_spread) : ( min_spreadPerAddress[msg.sender] > 0 ? min_spreadPerAddress[msg.sender] : (spreadForTag > 0 ? spreadForTag : min_spread) ); } function _buyFromAMMQuoteDoubleChance( address market, ISportsAMM.Position position, uint amount, uint useSafeBoxSkewImpact, bool useDefaultMinSpread, DoubleChanceStruct memory dcs ) internal view returns (uint returnQuote) { if (position == ISportsAMM.Position.Home) { (uint baseOdds1, uint baseOdds2) = sportAmmUtils.getBaseOddsForDoubleChance(market, _minOddsForMarket(market)); if (baseOdds1 > 0 && baseOdds2 > 0) { uint firstQuote = _buyFromAmmQuoteWithBaseOddsInternal( dcs.parentMarket, dcs.position1, amount, baseOdds1, useSafeBoxSkewImpact, 0, false, useDefaultMinSpread ); uint secondQuote = _buyFromAmmQuoteWithBaseOddsInternal( dcs.parentMarket, dcs.position2, amount, baseOdds2, useSafeBoxSkewImpact, 0, false, useDefaultMinSpread ); if (firstQuote > 0 && secondQuote > 0) { returnQuote = firstQuote + secondQuote; } } } } function _getAvailableOtherSide(address market, ISportsAMM.Position position) internal view returns (uint _availableOtherSide) { ISportsAMM.Position positionFirst = ISportsAMM.Position((uint(position) + 1) % 3); ISportsAMM.Position positionSecond = ISportsAMM.Position((uint(position) + 2) % 3); (uint _availableOtherSideFirst, uint _availableOtherSideSecond) = _getAvailableForPositions( market, positionFirst, positionSecond ); _availableOtherSide = _availableOtherSideFirst > _availableOtherSideSecond ? _availableOtherSideFirst : _availableOtherSideSecond; } function _getAvailableForPositions( address market, ISportsAMM.Position positionFirst, ISportsAMM.Position positionSecond ) internal view returns (uint _availableOtherSideFirst, uint _availableOtherSideSecond) { (uint baseOddsFirst, uint baseOddsSecond) = sportAmmUtils.obtainOddsMulti(market, positionFirst, positionSecond); uint minOdds = _minOddsForMarket(market); baseOddsFirst = baseOddsFirst < minOdds ? minOdds : baseOddsFirst; baseOddsSecond = baseOddsSecond < minOdds ? minOdds : baseOddsSecond; (uint balanceFirst, uint balanceSecond) = sportAmmUtils.getBalanceOfPositionsOnMarketByPositions( market, liquidityPool.getMarketPool(market), positionFirst, positionSecond ); _availableOtherSideFirst = _availableToBuyFromAMMWithBaseOdds( market, positionFirst, baseOddsFirst, balanceFirst, true ); _availableOtherSideSecond = _availableToBuyFromAMMWithBaseOdds( market, positionSecond, baseOddsSecond, balanceSecond, true ); } /// @notice Calculate the sUSD cost to buy an amount of available position options from AMM for specific market/game /// @param market The address of the SportPositional market of a game /// @param position The position (home/away/draw) quoted to buy from AMM /// @param amount The position amount quoted to buy from AMM /// @return _quote The sUSD cost for buying the `amount` of `position` options (tokens) from AMM for `market`. function buyFromAmmQuoteForParlayAMM( address market, ISportsAMM.Position position, uint amount ) public view returns (uint _quote) { uint baseOdds = _obtainOdds(market, position); uint minOdds = _minOddsForMarket(market); baseOdds = (baseOdds > 0 && baseOdds < minOdds) ? minOdds : baseOdds; _quote = _buyFromAmmQuoteWithBaseOdds( market, position, amount, baseOdds, 0, 0, false, true, _getDoubleChanceStruct(market) ); } /// @notice Calculate the sUSD cost to buy an amount of available position options from AMM for specific market/game /// @param market The address of the SportPositional market of a game /// @param position The position (home/away/draw) quoted to buy from AMM /// @param amount The position amount quoted to buy from AMM /// @param collateral The position amount quoted to buy from AMM /// @return collateralQuote The sUSD cost for buying the `amount` of `position` options (tokens) from AMM for `market`. /// @return sUSDToPay The sUSD cost for buying the `amount` of `position` options (tokens) from AMM for `market`. function buyFromAmmQuoteWithDifferentCollateral( address market, ISportsAMM.Position position, uint amount, address collateral ) public view returns (uint collateralQuote, uint sUSDToPay) { int128 curveIndex = _mapCollateralToCurveIndex(collateral); if (curveIndex > 0 && curveOnrampEnabled) { sUSDToPay = buyFromAmmQuote(market, 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; } } /// @notice Calculates the buy price impact for given position amount. Changes with every new purchase. /// @param market The address of the SportPositional market of a game /// @param position The position (home/away/draw) for which the buy price impact is calculated /// @param amount The position amount to calculate the buy price impact /// @return impact The buy price impact after the buy of the amount of positions for market function buyPriceImpact( address market, ISportsAMM.Position position, uint amount ) public view returns (int impact) { if (ISportPositionalMarketManager(manager).isDoubleChanceMarket(market)) { if (position == ISportsAMM.Position.Home) { (ISportsAMM.Position position1, ISportsAMM.Position position2, address parentMarket) = sportAmmUtils .getParentMarketPositions(market); int firstPriceImpact = buyPriceImpact(parentMarket, position1, amount); int secondPriceImpact = buyPriceImpact(parentMarket, position2, amount); impact = (firstPriceImpact + secondPriceImpact) / 2; } } else { uint _availableToBuyFromAMM = availableToBuyFromAMM(market, position); uint _availableOtherSide = _getAvailableOtherSide(market, position); if (amount > 0 && amount <= _availableToBuyFromAMM) { impact = _buyPriceImpact(market, position, amount, _availableToBuyFromAMM, _availableOtherSide); } } } /// @notice Obtains the oracle odds for `_position` of a given `_market` game. Odds do not contain price impact /// @param _market The address of the SportPositional market of a game /// @param _position The position (home/away/draw) to get the odds /// @return oddsToReturn The oracle odds for `_position` of a `_market` function obtainOdds(address _market, ISportsAMM.Position _position) external view returns (uint oddsToReturn) { oddsToReturn = _obtainOdds(_market, _position); } /// @notice Checks if a `market` is active for AMM trading /// @param market The address of the SportPositional market of a game /// @return isTrading Returns true if market is active, returns false if not active. function isMarketInAMMTrading(address market) public view returns (bool isTrading) { if (ISportPositionalMarketManager(manager).isActiveMarket(market)) { (uint maturity, ) = ISportPositionalMarket(market).times(); if (maturity >= block.timestamp) { isTrading = (maturity - block.timestamp) > minimalTimeLeftToMaturity; } } } /// @notice Checks the default odds for a `_market`. These odds take into account the price impact. /// @param _market The address of the SportPositional market of a game /// @return odds Returns the default odds for the `_market` including the price impact. function getMarketDefaultOdds(address _market, bool isSell) public view returns (uint[] memory odds) { odds = new uint[](ISportPositionalMarket(_market).optionsCount()); if (isMarketInAMMTrading(_market)) { for (uint i = 0; i < odds.length; i++) { odds[i] = buyFromAmmQuote(_market, ISportsAMM.Position(i), ONE); } } } // write methods /// @notice Buy amount of position for market/game from AMM using different collateral /// @param market The address of the SportPositional market of a game /// @param position The position (home/away/draw) to buy from AMM /// @param amount The position amount to buy from AMM /// @param expectedPayout The amount expected to pay in sUSD for the amount of position. Obtained by buyAMMQuote. /// @param additionalSlippage The slippage percentage for the payout /// @param collateral The address of the collateral used /// @param _referrer who referred the buyer to SportsAMM function buyFromAMMWithDifferentCollateralAndReferrer( address market, ISportsAMM.Position position, uint amount, uint expectedPayout, uint additionalSlippage, address collateral, address _referrer ) public nonReentrant whenNotPaused { if (_referrer != address(0)) { IReferrals(referrals).setReferrer(_referrer, msg.sender); } _buyFromAMMWithDifferentCollateral(market, position, amount, expectedPayout, additionalSlippage, collateral); } /// @notice Buy amount of position for market/game from AMM using different collateral /// @param market The address of the SportPositional market of a game /// @param position The position (home/away/draw) to buy from AMM /// @param amount The position amount to buy from AMM /// @param expectedPayout The amount expected to pay in sUSD for the amount of position. Obtained by buyAMMQuote. /// @param additionalSlippage The slippage percentage for the payout /// @param collateral The address of the collateral used function buyFromAMMWithDifferentCollateral( address market, ISportsAMM.Position position, uint amount, uint expectedPayout, uint additionalSlippage, address collateral ) public nonReentrant whenNotPaused { _buyFromAMMWithDifferentCollateral(market, position, amount, expectedPayout, additionalSlippage, collateral); } /// @notice Buy amount of position for market/game from AMM using sUSD /// @param market The address of the SportPositional market of a game /// @param position The position (home/away/draw) to buy from AMM /// @param amount The position amount to buy from AMM /// @param expectedPayout The sUSD amount expected to pay for buyuing the position amount. Obtained by buyAMMQuote. /// @param additionalSlippage The slippage percentage for the payout function buyFromAMM( address market, ISportsAMM.Position position, uint amount, uint expectedPayout, uint additionalSlippage ) public nonReentrant whenNotPaused { _buyFromAMM(BuyFromAMMParams(market, position, amount, expectedPayout, additionalSlippage, true, 0)); } /// @notice Buy amount of position for market/game from AMM using sUSD /// @param market The address of the SportPositional market of a game /// @param position The position (home/away/draw) to buy from AMM /// @param amount The position amount to buy from AMM /// @param expectedPayout The sUSD amount expected to pay for buying the position amount. Obtained by buyAMMQuote. /// @param additionalSlippage The slippage percentage for the payout function buyFromAMMWithReferrer( address market, ISportsAMM.Position position, uint amount, uint expectedPayout, uint additionalSlippage, address _referrer ) public nonReentrant whenNotPaused { if (_referrer != address(0)) { IReferrals(referrals).setReferrer(_referrer, msg.sender); } _buyFromAMM(BuyFromAMMParams(market, position, amount, expectedPayout, additionalSlippage, true, 0)); } /// @notice Send tokens from this contract to the destination address /// @param tokens to iterate and transfer /// @param account Address where to send the tokens /// @param amount Amount of tokens to be sent /// @param all ignore amount and send whole balance function transferTokens( address[] calldata tokens, address payable account, uint amount, bool all ) external onlyOwner { require(tokens.length > 0, "tokens array cant be empty"); for (uint256 index = 0; index < tokens.length; index++) { if (all) { IERC20Upgradeable(tokens[index]).safeTransfer( account, IERC20Upgradeable(tokens[index]).balanceOf(address(this)) ); } else { IERC20Upgradeable(tokens[index]).safeTransfer(account, amount); } } } // setters /// @notice Setting all key parameters for AMM /// @param _minimalTimeLeftToMaturity The time period in seconds. /// @param _minSpread Minimum spread percentage expressed in ether unit (uses 18 decimals -> 1% = 0.01*1e18) /// @param _maxSpread Maximum spread percentage expressed in ether unit (uses 18 decimals -> 1% = 0.01*1e18) /// @param _minSupportedOdds Minimal oracle odd in ether unit (18 decimals) /// @param _maxSupportedOdds Maximum oracle odds in ether unit (18 decimals) /// @param _safeBoxImpact Percentage expressed in ether unit (uses 18 decimals -> 1% = 0.01*1e18) /// @param _referrerFee how much of a fee to pay to referrers function setParameters( uint _minimalTimeLeftToMaturity, uint _minSpread, uint _maxSpread, uint _minSupportedOdds, uint _maxSupportedOdds, uint _safeBoxImpact, uint _referrerFee, uint _threshold ) external onlyOwner { minimalTimeLeftToMaturity = _minimalTimeLeftToMaturity; min_spread = _minSpread; max_spread = _maxSpread; minSupportedOdds = _minSupportedOdds; maxSupportedOdds = _maxSupportedOdds; safeBoxImpact = _safeBoxImpact; referrerFee = _referrerFee; thresholdForOddsUpdate = _threshold; emit ParametersUpdated( _minimalTimeLeftToMaturity, _minSpread, _maxSpread, _minSupportedOdds, _maxSupportedOdds, _safeBoxImpact, _referrerFee, _threshold ); } /// @notice Setting the main addresses for SportsAMM /// @param _safeBox Address of the Safe Box /// @param _sUSD Address of the sUSD /// @param _theRundownConsumer Address of Therundown consumer /// @param _stakingThales Address of Staking contract /// @param _referrals contract for referrals storage /// @param _wrapper contract for calling wrapper contract /// @param _lp contract for managing liquidity pools function setAddresses( address _safeBox, IERC20Upgradeable _sUSD, address _theRundownConsumer, IStakingThales _stakingThales, address _referrals, address _parlayAMM, address _wrapper, address _lp, address _riskManager ) external onlyOwner { safeBox = _safeBox; sUSD = _sUSD; theRundownConsumer = _theRundownConsumer; stakingThales = _stakingThales; referrals = _referrals; parlayAMM = _parlayAMM; wrapper = ITherundownConsumerWrapper(_wrapper); liquidityPool = SportAMMLiquidityPool(_lp); riskManager = ISportAMMRiskManager(_riskManager); emit AddressesUpdated( _safeBox, _sUSD, _theRundownConsumer, _stakingThales, _referrals, _parlayAMM, _wrapper, _lp, _riskManager ); } /// @notice Setting the Sport Positional Manager contract address /// @param _manager Address of Staking contract function setSportsPositionalMarketManager(address _manager) external onlyOwner { if (address(_manager) != address(0)) { sUSD.approve(address(_manager), 0); } manager = _manager; sUSD.approve(manager, MAX_APPROVAL); emit SetSportsPositionalMarketManager(_manager); } /// @notice Updates contract parametars /// @param _address which has a specific safe box fee /// @param newSBFee the SafeBox fee for address /// @param newMSFee the min_spread fee for address function setSafeBoxFeeAndMinSpreadPerAddress( address _address, uint newSBFee, uint newMSFee ) external onlyOwner { safeBoxFeePerAddress[_address] = newSBFee; min_spreadPerAddress[_address] = newMSFee; } /// @notice Setting the Curve collateral addresses for all collaterals /// @param _curveSUSD Address of the Curve contract /// @param _dai Address of the DAI contract /// @param _usdc Address of the USDC contract /// @param _usdt Address of the USDT (Tether) contract /// @param _curveOnrampEnabled Enabling or restricting the use of multicollateral /// @param _maxAllowedPegSlippagePercentage maximum discount AMM accepts for sUSD purchases function setCurveSUSD( address _curveSUSD, address _dai, address _usdc, address _usdt, bool _curveOnrampEnabled, uint _maxAllowedPegSlippagePercentage ) external onlyOwner { curveSUSD = ICurveSUSD(_curveSUSD); dai = _dai; usdc = _usdc; usdt = _usdt; IERC20Upgradeable(dai).approve(_curveSUSD, MAX_APPROVAL); IERC20Upgradeable(usdc).approve(_curveSUSD, MAX_APPROVAL); IERC20Upgradeable(usdt).approve(_curveSUSD, MAX_APPROVAL); // not needed unless selling into different collateral is enabled //sUSD.approve(_curveSUSD, MAX_APPROVAL); curveOnrampEnabled = _curveOnrampEnabled; maxAllowedPegSlippagePercentage = _maxAllowedPegSlippagePercentage; } function setPaused(bool _setPausing) external onlyOwner { _setPausing ? _pause() : _unpause(); } function setMinSupportedOddsAndMaxSpreadPerSportPerSport( uint _sportID, uint _minSupportedOdds, uint _maxSpreadPerSport ) external onlyOwner { minSupportedOddsPerSport[_sportID] = _minSupportedOdds; maxSpreadPerSport[_sportID] = _maxSpreadPerSport; emit SetMinSupportedOddsAndMaxSpreadPerSport(_sportID, _minSupportedOdds, _maxSpreadPerSport); } /// @notice Setting the Min Spread per Sport ID /// @param _tag1 The first tagID used for each market /// @param _tag2 The second tagID used for each market /// @param _minSpread The min spread amount used for the sportID function setMinSpreadPerSport( uint _tag1, uint _tag2, uint _minSpread ) external onlyOwner { minSpreadPerSport[_tag1][_tag2] = _minSpread; emit SetMinSpreadPerSport(_tag1, _tag2, _minSpread); } /// @notice used to update gamified Staking bonuses from Parlay contract /// @param _account Address to update volume for /// @param _amount of the volume function updateParlayVolume(address _account, uint _amount) external { require(msg.sender == parlayAMM, "Invalid caller"); if (address(stakingThales) != address(0)) { stakingThales.updateVolume(_account, _amount); } } /// @notice Updates contract parametars /// @param _ammUtils address of AMMUtils function setAmmUtils(SportsAMMUtils _ammUtils) external onlyOwner { sportAmmUtils = _ammUtils; } // Internal function _buyFromAMMWithDifferentCollateral( address market, ISportsAMM.Position position, uint amount, uint expectedPayout, uint additionalSlippage, address collateral ) internal { int128 curveIndex = _mapCollateralToCurveIndex(collateral); require(curveIndex > 0 && curveOnrampEnabled, "unsupported collateral"); (uint collateralQuote, uint susdQuote) = buyFromAmmQuoteWithDifferentCollateral( market, position, amount, collateral ); uint transformedCollateralForPegCheck = collateral == usdc || collateral == usdt ? collateralQuote * (1e12) : collateralQuote; require( maxAllowedPegSlippagePercentage > 0 && transformedCollateralForPegCheck >= (susdQuote * (ONE - (maxAllowedPegSlippagePercentage))) / ONE, "Max peg slippage" ); require((collateralQuote * ONE) / (expectedPayout) <= (ONE + additionalSlippage), "High slippage"); IERC20Upgradeable collateralToken = IERC20Upgradeable(collateral); collateralToken.safeTransferFrom(msg.sender, address(this), collateralQuote); curveSUSD.exchange_underlying(curveIndex, 0, collateralQuote, susdQuote); return _buyFromAMM(BuyFromAMMParams(market, position, amount, susdQuote, additionalSlippage, false, susdQuote)); } function _checkMarketValidityAndOptionsCount(address market, ISportsAMM.Position position) internal view { require(isMarketInAMMTrading(market), "Not trading"); uint optionsCount = ISportPositionalMarket(market).optionsCount(); require(optionsCount > uint(position), "Invalid pos"); } function _buyFromAMM(BuyFromAMMParams memory params) internal { _checkMarketValidityAndOptionsCount(params.market, params.position); DoubleChanceStruct memory dcs = _getDoubleChanceStruct(params.market); require(!dcs.isDoubleChance || params.position == ISportsAMM.Position.Home, "Invalid pos"); uint baseOdds = _obtainOddsWithDC(params.market, params.position, dcs.isDoubleChance); require(baseOdds > 0, "No base odds"); uint minOdds = _minOddsForMarket(params.market); baseOdds = baseOdds < minOdds ? minOdds : baseOdds; uint availableInContract = sportAmmUtils.balanceOfPositionOnMarket( params.market, params.position, liquidityPool.getMarketPool(params.market) ); uint availableToBuyFromAMMatm = _availableToBuyFromAMMInternal( params.market, params.position, baseOdds, availableInContract, true, dcs ); require(params.amount > ZERO_POINT_ONE && params.amount <= availableToBuyFromAMMatm, "Low liquidity || 0"); if (params.sendSUSD) { params.sUSDPaid = _buyFromAmmQuoteWithBaseOdds( params.market, params.position, params.amount, baseOdds, _getSafeBoxFeePerAddress(msg.sender), availableToBuyFromAMMatm, true, false, dcs ); require((params.sUSDPaid * ONE) / params.expectedPayout <= (ONE + params.additionalSlippage), "High slippage"); sUSD.safeTransferFrom(msg.sender, address(this), params.sUSDPaid); } address parent = dcs.isDoubleChance || ISportPositionalMarket(params.market).isChild() ? address(ISportPositionalMarket(params.market).parentMarket()) : params.market; if (dcs.isDoubleChance) { ISportPositionalMarket(params.market).mint(params.amount); _mintParentPositions(params.market, params.amount, dcs); (address parentMarketPosition1, address parentMarketPosition2) = sportAmmUtils.getParentMarketPositionAddresses( params.market ); _getDoubleChanceOptions(params.amount, parentMarketPosition1, params.market); _getDoubleChanceOptions(params.amount, parentMarketPosition2, params.market); IERC20Upgradeable(parentMarketPosition1).safeTransfer(params.market, params.amount); IERC20Upgradeable(parentMarketPosition2).safeTransfer(params.market, params.amount); } else { uint toMint = availableInContract < params.amount ? params.amount - availableInContract : 0; if (toMint > 0) { liquidityPool.commitTrade(params.market, toMint); ISportPositionalMarket(params.market).mint(toMint); spentOnGame[params.market] = spentOnGame[params.market] + toMint; spentOnParent[parent] += toMint; } liquidityPool.getOptionsForBuy(params.market, params.amount - toMint, params.position); } (IPosition home, IPosition away, IPosition draw) = ISportPositionalMarket(params.market).getOptions(); IPosition target = params.position == ISportsAMM.Position.Home ? home : params.position == ISportsAMM.Position.Away ? away : draw; IERC20Upgradeable(address(target)).safeTransfer(msg.sender, params.amount); if ( !dcs.isDoubleChance && thresholdForOddsUpdate > 0 && (params.amount - params.sUSDPaid) >= thresholdForOddsUpdate ) { (, uint tag2) = _getTagsForMarket(params.market); if (tag2 == TAG_NUMBER_PLAYERS) { wrapper.callUpdateOddsForSpecificPlayerProps(params.market); } else { wrapper.callUpdateOddsForSpecificGame(params.market); } } _updateSpentOnMarketOnBuy( dcs.isDoubleChance ? address(ISportPositionalMarket(params.market).parentMarket()) : params.market, parent, params.sUSDPaid, msg.sender ); require(riskManager.isTotalSpendingLessThanTotalRisk(spentOnParent[parent], parent), "Risk is to high!"); _sendMintedPositionsAndUSDToLiquidityPool( dcs.isDoubleChance ? address(ISportPositionalMarket(params.market).parentMarket()) : params.market ); if (address(stakingThales) != address(0)) { stakingThales.updateVolume(msg.sender, params.sUSDPaid); } emit BoughtFromAmm( msg.sender, params.market, params.position, params.amount, params.sUSDPaid, address(sUSD), address(target) ); } function _getDoubleChanceOptions( uint amount, address position, address market ) internal { uint balanceHeld = IERC20Upgradeable(position).balanceOf(address(this)); if (amount > balanceHeld) { liquidityPool.getOptionsForBuyByAddress( address(ISportPositionalMarket(market).parentMarket()), amount - balanceHeld, position ); } } function _availableToBuyFromAMMInternal( address market, ISportsAMM.Position position, uint baseOdds, uint balance, bool useBalance, DoubleChanceStruct memory dcs ) internal view returns (uint _available) { if (dcs.isDoubleChance) { if (position == ISportsAMM.Position.Home && (baseOdds > 0 && baseOdds < maxSupportedOdds)) { (uint availableFirst, uint availableSecond) = _getAvailableForPositions( dcs.parentMarket, dcs.position1, dcs.position2 ); _available = availableFirst > availableSecond ? availableSecond : availableFirst; } } else { uint minOdds = _minOddsForMarket(market); baseOdds = baseOdds < minOdds ? minOdds : baseOdds; _available = _availableToBuyFromAMMWithBaseOdds(market, position, baseOdds, balance, useBalance); } } function _availableToBuyFromAMMWithBaseOdds( address market, ISportsAMM.Position position, uint baseOdds, uint balance, bool useBalance ) internal view returns (uint availableAmount) { if (baseOdds > 0 && baseOdds < maxSupportedOdds) { baseOdds = (baseOdds * (ONE + min_spread)) / ONE; balance = useBalance ? balance : sportAmmUtils.balanceOfPositionOnMarket(market, position, liquidityPool.getMarketPool(market)); availableAmount = sportAmmUtils.calculateAvailableToBuy( riskManager.calculateCapToBeUsed(market), spentOnGame[market], baseOdds, balance, _maxSpreadForMarket(market) ); } } function _obtainOdds(address _market, ISportsAMM.Position _position) internal view returns (uint) { if (ISportPositionalMarketManager(manager).isDoubleChanceMarket(_market)) { if (_position == ISportsAMM.Position.Home) { return sportAmmUtils.getBaseOddsForDoubleChanceSum(_market, _minOddsForMarket(_market)); } } return sportAmmUtils.obtainOdds(_market, _position); } function _obtainOddsWithDC( address _market, ISportsAMM.Position _position, bool isDoubleChance ) internal view returns (uint) { if (isDoubleChance) { return sportAmmUtils.getBaseOddsForDoubleChanceSum(_market, _minOddsForMarket(_market)); } return sportAmmUtils.obtainOdds(_market, _position); } function _getSafeBoxFeePerAddress(address toCheck) internal view returns (uint toReturn) { if (toCheck != parlayAMM) { return safeBoxFeePerAddress[toCheck] > 0 ? safeBoxFeePerAddress[toCheck] : safeBoxImpact; } } function _minOddsForMarket(address _market) internal view returns (uint minOdds) { (uint tag1, ) = _getTagsForMarket(_market); minOdds = minSupportedOddsPerSport[tag1] > 0 ? minSupportedOddsPerSport[tag1] : minSupportedOdds; } function _maxSpreadForMarket(address _market) internal view returns (uint maxSpread) { (uint tag1, ) = _getTagsForMarket(_market); maxSpread = maxSpreadPerSport[tag1] > 0 ? maxSpreadPerSport[tag1] : max_spread; } function _sendMintedPositionsAndUSDToLiquidityPool(address market) internal { address _liquidityPool = liquidityPool.getOrCreateMarketPool(market); if (sUSD.balanceOf(address(this)) > 0) { sUSD.safeTransfer(_liquidityPool, sUSD.balanceOf(address(this))); } (IPosition home, IPosition away, IPosition draw) = ISportPositionalMarket(market).getOptions(); (uint homeBalance, uint awayBalance, uint drawBalance) = sportAmmUtils.getBalanceOfPositionsOnMarket( market, address(this) ); if (homeBalance > 0) { IERC20Upgradeable(address(home)).safeTransfer(_liquidityPool, homeBalance); } if (awayBalance > 0) { IERC20Upgradeable(address(away)).safeTransfer(_liquidityPool, awayBalance); } if (drawBalance > 0) { IERC20Upgradeable(address(draw)).safeTransfer(_liquidityPool, drawBalance); } } function _updateSpentOnMarketOnBuy( address market, address parent, uint sUSDPaid, address buyer ) internal { uint safeBoxShare; uint sbimpact = _getSafeBoxFeePerAddress(buyer); if (sbimpact > 0) { safeBoxShare = sUSDPaid - (sUSDPaid * ONE) / (ONE + sbimpact); sUSD.safeTransfer(safeBox, safeBoxShare); } uint toSubtract = ISportPositionalMarketManager(manager).reverseTransformCollateral(sUSDPaid - safeBoxShare); spentOnGame[market] = spentOnGame[market] <= toSubtract ? 0 : (spentOnGame[market] = spentOnGame[market] - toSubtract); spentOnParent[parent] = spentOnParent[parent] <= toSubtract ? 0 : (spentOnParent[parent] = spentOnParent[parent] - toSubtract); if (referrerFee > 0 && referrals != address(0)) { uint referrerShare = sUSDPaid - ((sUSDPaid * ONE) / (ONE + referrerFee)); _handleReferrer(buyer, referrerShare, sUSDPaid); } } function _buyPriceImpact( address market, ISportsAMM.Position position, uint amount, uint _availableToBuyFromAMM, uint _availableToBuyFromAMMOtherSide ) internal view returns (int priceImpact) { return sportAmmUtils.getBuyPriceImpact( SportsAMMUtils.PriceImpactParams( market, position, amount, _availableToBuyFromAMM, _availableToBuyFromAMMOtherSide, liquidityPool, _maxSpreadForMarket(market), _minOddsForMarket(market) ) ); } function _handleReferrer( address buyer, uint referrerShare, uint volume ) internal { address referrer = IReferrals(referrals).sportReferrals(buyer); if (referrer != address(0) && referrerFee > 0) { sUSD.safeTransfer(referrer, referrerShare); emit ReferrerPaid(referrer, buyer, referrerShare, volume); } } function _mintParentPositions( address market, uint amount, DoubleChanceStruct memory dcs ) internal { (uint availableInContract1, uint availableInContract2) = sportAmmUtils.getBalanceOfPositionsOnMarketByPositions( dcs.parentMarket, liquidityPool.getMarketPool(market), dcs.position1, dcs.position2 ); uint toMintPosition1 = availableInContract1 < amount ? amount - availableInContract1 : 0; uint toMintPosition2 = availableInContract2 < amount ? amount - availableInContract2 : 0; uint toMint = toMintPosition1 < toMintPosition2 ? toMintPosition2 : toMintPosition1; if (toMint > 0) { liquidityPool.commitTrade(dcs.parentMarket, toMint); ISportPositionalMarket(dcs.parentMarket).mint(toMint); spentOnGame[dcs.parentMarket] = spentOnGame[dcs.parentMarket] + toMint; spentOnParent[dcs.parentMarket] += toMint; } } function _getDoubleChanceStruct(address market) internal view returns (DoubleChanceStruct memory) { if (!ISportPositionalMarketManager(manager).isDoubleChanceMarket(market)) { return DoubleChanceStruct(false, ISportsAMM.Position.Home, ISportsAMM.Position.Away, address(0)); } else { (ISportsAMM.Position position1, ISportsAMM.Position position2, address parentMarket) = sportAmmUtils .getParentMarketPositions(market); return DoubleChanceStruct(true, position1, position2, parentMarket); } } function _mapCollateralToCurveIndex(address collateral) internal view returns (int128 mappedValue) { if (collateral == dai) { mappedValue = 1; } if (collateral == usdc) { mappedValue = 2; } if (collateral == usdt) { mappedValue = 3; } } // events event BoughtFromAmm( address buyer, address market, ISportsAMM.Position position, uint amount, uint sUSDPaid, address susd, address asset ); event ParametersUpdated( uint _minimalTimeLeftToMaturity, uint _minSpread, uint _maxSpread, uint _minSupportedOdds, uint _maxSupportedOdds, uint _safeBoxImpact, uint _referrerFee, uint threshold ); event AddressesUpdated( address _safeBox, IERC20Upgradeable _sUSD, address _theRundownConsumer, IStakingThales _stakingThales, address _referrals, address _parlayAMM, address _wrapper, address _lp, address _riskManager ); event SetSportsPositionalMarketManager(address _manager); event ReferrerPaid(address refferer, address trader, uint amount, uint volume); event SetMinSpreadPerSport(uint _tag1, uint _tag2, uint _spread); event SetMinSupportedOddsAndMaxSpreadPerSport(uint _sport, uint _minSupportedOddsPerSport, uint _maxSpreadPerSport); }
// 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"); } } }
// 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; }
// 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)); } }
// 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); }
// 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; }
// 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"); } }
// 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); }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; import "../interfaces/IPositionalMarketManager.sol"; import "../interfaces/IPosition.sol"; import "../interfaces/IPriceFeed.sol"; interface ISportPositionalMarket { /* ========== TYPES ========== */ enum Phase { Trading, Maturity, Expiry } enum Side { Cancelled, Home, Away, Draw } /* ========== VIEWS / VARIABLES ========== */ function getOptions() external view returns ( IPosition home, IPosition away, IPosition draw ); function times() external view returns (uint maturity, uint destruction); function initialMint() external view returns (uint); function getGameDetails() external view returns (bytes32 gameId, string memory gameLabel); function getGameId() external view returns (bytes32); function deposited() external view returns (uint); function optionsCount() external view returns (uint); function creator() external view returns (address); function resolved() external view returns (bool); function cancelled() external view returns (bool); function paused() external view returns (bool); function phase() external view returns (Phase); function canResolve() external view returns (bool); function result() external view returns (Side); function isChild() external view returns (bool); function tags(uint idx) external view returns (uint); function getTags() external view returns (uint tag1, uint tag2); function getTagsLength() external view returns (uint tagsLength); function getParentMarketPositions() external view returns (IPosition position1, IPosition position2); function getStampedOdds() external view returns ( uint, uint, uint ); function balancesOf(address account) external view returns ( uint home, uint away, uint draw ); function totalSupplies() external view returns ( uint home, uint away, uint draw ); function isDoubleChance() external view returns (bool); function parentMarket() external view returns (ISportPositionalMarket); /* ========== MUTATIVE FUNCTIONS ========== */ function setPaused(bool _paused) external; function updateDates(uint256 _maturity, uint256 _expiry) external; function mint(uint value) external; function exerciseOptions() external; function restoreInvalidOdds( uint _homeOdds, uint _awayOdds, uint _drawOdds ) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../interfaces/ISportPositionalMarket.sol"; interface ISportPositionalMarketManager { /* ========== VIEWS / VARIABLES ========== */ function marketCreationEnabled() external view returns (bool); function totalDeposited() external view returns (uint); function numActiveMarkets() external view returns (uint); function activeMarkets(uint index, uint pageSize) external view returns (address[] memory); function numMaturedMarkets() external view returns (uint); function maturedMarkets(uint index, uint pageSize) external view returns (address[] memory); function isActiveMarket(address candidate) external view returns (bool); function isDoubleChanceMarket(address candidate) external view returns (bool); function isDoubleChanceSupported() external view returns (bool); function isKnownMarket(address candidate) external view returns (bool); function getActiveMarketAddress(uint _index) external view returns (address); function transformCollateral(uint value) external view returns (uint); function reverseTransformCollateral(uint value) external view returns (uint); function isMarketPaused(address _market) external view returns (bool); function expiryDuration() external view returns (uint); function isWhitelistedAddress(address _address) external view returns (bool); function getOddsObtainer() external view returns (address obtainer); /* ========== MUTATIVE FUNCTIONS ========== */ function createMarket( bytes32 gameId, string memory gameLabel, uint maturity, uint initialMint, // initial sUSD to mint options for, uint positionCount, uint[] memory tags, bool isChild, address parentMarket ) external returns (ISportPositionalMarket); function setMarketPaused(address _market, bool _paused) external; function updateDatesForMarket(address _market, uint256 _newStartTime) external; function resolveMarket(address market, uint outcome) external; function expireMarkets(address[] calldata market) external; function transferSusdTo( address sender, address receiver, uint amount ) external; function queryMintsAndMaturityStatusForPlayerProps(address[] memory _playerPropsMarkets) external view returns ( bool[] memory _hasAnyMintsArray, bool[] memory _isMaturedArray, bool[] memory _isResolvedArray ); }
// 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; }
// 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); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface ITherundownConsumer { struct GameCreate { bytes32 gameId; uint256 startTime; int24 homeOdds; int24 awayOdds; int24 drawOdds; string homeTeam; string awayTeam; } // view functions function supportedSport(uint _sportId) external view returns (bool); function gameOnADate(bytes32 _gameId) external view returns (uint); function isGameResolvedOrCanceled(bytes32 _gameId) external view returns (bool); function getNormalizedOddsForMarket(address _market) external view returns (uint[] memory); function getGamesPerDatePerSport(uint _sportId, uint _date) external view returns (bytes32[] memory); function getGamePropsForOdds(address _market) external view returns ( uint, uint, bytes32 ); function gameIdPerMarket(address _market) external view returns (bytes32); function getGameCreatedById(bytes32 _gameId) external view returns (GameCreate memory); function isChildMarket(address _market) external view returns (bool); function gameFulfilledCreated(bytes32 _gameId) external view returns (bool); // write functions function fulfillGamesCreated( bytes32 _requestId, bytes[] memory _games, uint _sportsId, uint _date ) external; function fulfillGamesResolved( bytes32 _requestId, bytes[] memory _games, uint _sportsId ) external; function fulfillGamesOdds(bytes32 _requestId, bytes[] memory _games) external; function setPausedByCanceledStatus(address _market, bool _flag) external; function setGameIdPerChildMarket(bytes32 _gameId, address _child) external; function pauseOrUnpauseMarket(address _market, bool _pause) external; function pauseOrUnpauseMarketForPlayerProps( address _market, bool _pause, bool _invalidOdds, bool _circuitBreakerMain ) external; function setChildMarkets( bytes32 _gameId, address _main, address _child, bool _isSpread, int16 _spreadHome, uint24 _totalOver ) external; function resolveMarketManually( address _market, uint _outcome, uint8 _homeScore, uint8 _awayScore, bool _usebackupOdds ) external; function getOddsForGame(bytes32 _gameId) external view returns ( int24, int24, int24 ); function sportsIdPerGame(bytes32 _gameId) external view returns (uint); function getGameStartTime(bytes32 _gameId) external view returns (uint256); function marketPerGameId(bytes32 _gameId) external view returns (address); function marketResolved(address _market) external view returns (bool); function marketCanceled(address _market) external view returns (bool); function invalidOdds(address _market) external view returns (bool); function isPausedByCanceledStatus(address _market) external view returns (bool); function isSportOnADate(uint _date, uint _sportId) external view returns (bool); function isSportTwoPositionsSport(uint _sportsId) external view returns (bool); }
// 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 }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; interface IReferrals { function referrals(address) external view returns (address); function getReferrerFee(address) external view returns (uint); function sportReferrals(address) external view returns (address); function setReferrer(address, address) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../interfaces/ISportAMMRiskManager.sol"; interface ISportsAMM { /* ========== VIEWS / VARIABLES ========== */ enum Position { Home, Away, Draw } struct SellRequirements { address user; address market; Position position; uint amount; uint expectedPayout; uint additionalSlippage; } function theRundownConsumer() external view returns (address); function riskManager() external view returns (ISportAMMRiskManager riskManager); function getMarketDefaultOdds(address _market, bool isSell) external view returns (uint[] memory); function isMarketInAMMTrading(address _market) external view returns (bool); function isMarketForSportOnePositional(uint _tag) external view returns (bool); function availableToBuyFromAMM(address market, Position position) external view returns (uint _available); function parlayAMM() external view returns (address); function minSupportedOdds() external view returns (uint); function maxSupportedOdds() external view returns (uint); function minSupportedOddsPerSport(uint) external view returns (uint); function min_spread() external view returns (uint); function max_spread() external view returns (uint); function minimalTimeLeftToMaturity() external view returns (uint); function getSpentOnGame(address market) external view returns (uint); function safeBoxImpact() external view returns (uint); function manager() external view returns (address); function getLiquidityPool() external view returns (address); function buyFromAMM( address market, Position position, uint amount, uint expectedPayout, uint additionalSlippage ) external; function buyFromAmmQuote( address market, Position position, uint amount ) external view returns (uint); function buyFromAmmQuoteForParlayAMM( address market, Position position, uint amount ) external view returns (uint); function updateParlayVolume(address _account, uint _amount) external; function buyPriceImpact( address market, ISportsAMM.Position position, uint amount ) external view returns (int impact); function obtainOdds(address _market, ISportsAMM.Position _position) external view returns (uint oddsToReturn); function buyFromAmmQuoteWithDifferentCollateral( address market, ISportsAMM.Position position, uint amount, address collateral ) external view returns (uint collateralQuote, uint sUSDToPay); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface ITherundownConsumerWrapper { function callUpdateOddsForSpecificGame(address _marketAddress) external; function callUpdateOddsForSpecificPlayerProps(address _marketAddress) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface ISportAMMRiskManager { function calculateCapToBeUsed(address _market) external view returns (uint toReturn); function isTotalSpendingLessThanTotalRisk(uint _totalSpent, address _market) external view returns (bool _isNotRisky); function isMarketForSportOnePositional(uint _tag) external view returns (bool); function isMarketForPlayerPorpsOnePositional(uint _tag) external view returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; import "@openzeppelin/contracts-4.4.1/token/ERC20/IERC20.sol"; import "../interfaces/ISportPositionalMarket.sol"; import "../interfaces/ISportPositionalMarketManager.sol"; import "../interfaces/IPosition.sol"; import "../interfaces/ITherundownConsumer.sol"; import "../interfaces/ISportsAMM.sol"; import "../interfaces/ISportAMMRiskManager.sol"; import "./LiquidityPool/SportAMMLiquidityPool.sol"; /// @title Sports AMM utils contract SportsAMMUtils { uint private constant ONE = 1e18; uint private constant ZERO_POINT_ONE = 1e17; uint private constant ONE_PERCENT = 1e16; uint private constant MAX_APPROVAL = type(uint256).max; int private constant ONE_INT = 1e18; int private constant ONE_PERCENT_INT = 1e16; uint public constant TAG_NUMBER_PLAYERS = 10010; ISportsAMM public sportsAMM; constructor(address _sportsAMM) { sportsAMM = ISportsAMM(_sportsAMM); } struct DiscountParams { uint balancePosition; uint balanceOtherSide; uint amount; uint availableToBuyFromAMM; uint max_spread; } struct NegativeDiscountsParams { uint amount; uint balancePosition; uint balanceOtherSide; uint _availableToBuyFromAMMOtherSide; uint _availableToBuyFromAMM; uint pricePosition; uint priceOtherPosition; uint max_spread; } struct PriceImpactParams { address market; ISportsAMM.Position position; uint amount; uint _availableToBuyFromAMM; uint _availableToBuyFromAMMOtherSide; SportAMMLiquidityPool liquidityPool; uint max_spread; uint minSupportedOdds; } function buyPriceImpactImbalancedSkew( uint amount, uint balanceOtherSide, uint balancePosition, uint balanceOtherSideAfter, uint balancePositionAfter, uint availableToBuyFromAMM, uint max_spread ) public view returns (uint) { uint maxPossibleSkew = balanceOtherSide + availableToBuyFromAMM - balancePosition; uint skew = balanceOtherSideAfter - (balancePositionAfter); uint newImpact = (max_spread * ((skew * ONE) / (maxPossibleSkew))) / ONE; if (balancePosition > 0) { uint newPriceForMintedOnes = newImpact / 2; uint tempMultiplier = (amount - balancePosition) * newPriceForMintedOnes; return (tempMultiplier * ONE) / (amount) / ONE; } else { uint previousSkew = balanceOtherSide; uint previousImpact = (max_spread * ((previousSkew * ONE) / maxPossibleSkew)) / ONE; return (newImpact + previousImpact) / 2; } } function calculateDiscount(DiscountParams memory params) public view returns (int) { uint currentBuyImpactOtherSide = buyPriceImpactImbalancedSkew( params.amount, params.balancePosition, params.balanceOtherSide, params.balanceOtherSide > ONE ? params.balancePosition : params.balancePosition + (ONE - params.balanceOtherSide), params.balanceOtherSide > ONE ? params.balanceOtherSide - ONE : 0, params.availableToBuyFromAMM, params.max_spread ); uint startDiscount = currentBuyImpactOtherSide; uint tempMultiplier = params.balancePosition - params.amount; uint finalDiscount = ((startDiscount / 2) * ((tempMultiplier * ONE) / params.balancePosition + ONE)) / ONE; return -int(finalDiscount); } function calculateDiscountFromNegativeToPositive(NegativeDiscountsParams memory params) public view returns (int priceImpact) { uint amountToBeMinted = params.amount - params.balancePosition; uint sum1 = params.balanceOtherSide + params.balancePosition; uint sum2 = params.balanceOtherSide + amountToBeMinted; uint red3 = params._availableToBuyFromAMM - params.balancePosition; uint positiveSkew = buyPriceImpactImbalancedSkew(amountToBeMinted, sum1, 0, sum2, 0, red3, params.max_spread); uint skew = (params.priceOtherPosition * positiveSkew) / params.pricePosition; int discount = calculateDiscount( DiscountParams( params.balancePosition, params.balanceOtherSide, params.balancePosition, params._availableToBuyFromAMMOtherSide, params.max_spread ) ); int discountBalance = int(params.balancePosition) * discount; int discountMinted = int(amountToBeMinted * skew); int amountInt = int(params.balancePosition + amountToBeMinted); priceImpact = (discountBalance + discountMinted) / amountInt; if (priceImpact > 0) { int numerator = int(params.pricePosition) * priceImpact; priceImpact = numerator / int(params.priceOtherPosition); } } function calculateTempQuote( int skewImpact, uint baseOdds, uint safeBoxImpact, uint amount ) public pure returns (int tempQuote) { if (skewImpact >= 0) { int impactPrice = ((ONE_INT - int(baseOdds)) * skewImpact) / ONE_INT; // add 2% to the price increase to avoid edge cases on the extremes impactPrice = (impactPrice * (ONE_INT + (ONE_PERCENT_INT * 2))) / ONE_INT; tempQuote = (int(amount) * (int(baseOdds) + impactPrice)) / ONE_INT; } else { tempQuote = ((int(amount)) * ((int(baseOdds) * (ONE_INT + skewImpact)) / ONE_INT)) / ONE_INT; } tempQuote = (tempQuote * (ONE_INT + (int(safeBoxImpact)))) / ONE_INT; } function calculateAvailableToBuy( uint capUsed, uint spentOnThisGame, uint baseOdds, uint balance, uint max_spread ) public view returns (uint availableAmount) { uint discountedPrice = (baseOdds * (ONE - max_spread / 2)) / ONE; uint additionalBufferFromSelling = (balance * discountedPrice) / ONE; if ((capUsed + additionalBufferFromSelling) > spentOnThisGame) { uint availableUntilCapSUSD = capUsed + additionalBufferFromSelling - spentOnThisGame; if (availableUntilCapSUSD > capUsed) { availableUntilCapSUSD = capUsed; } uint midImpactPriceIncrease = ((ONE - baseOdds) * (max_spread / 2)) / ONE; uint divider_price = ONE - (baseOdds + midImpactPriceIncrease); availableAmount = balance + ((availableUntilCapSUSD * ONE) / divider_price); } } function getCanExercize(address market, address toCheck) public view returns (bool canExercize) { if ( ISportPositionalMarketManager(sportsAMM.manager()).isKnownMarket(market) && !ISportPositionalMarket(market).paused() && ISportPositionalMarket(market).resolved() ) { (IPosition home, IPosition away, IPosition draw) = ISportPositionalMarket(market).getOptions(); if ( (home.getBalanceOf(address(toCheck)) > 0) || (away.getBalanceOf(address(toCheck)) > 0) || (ISportPositionalMarket(market).optionsCount() > 2 && draw.getBalanceOf(address(toCheck)) > 0) ) { canExercize = true; } } } function obtainOdds(address _market, ISportsAMM.Position _position) public view returns (uint oddsToReturn) { address theRundownConsumer = sportsAMM.theRundownConsumer(); ISportAMMRiskManager riskManager = sportsAMM.riskManager(); if (ISportPositionalMarket(_market).optionsCount() > uint(_position)) { uint[] memory odds = new uint[](ISportPositionalMarket(_market).optionsCount()); odds = ITherundownConsumer(theRundownConsumer).getNormalizedOddsForMarket(_market); (uint firstTag, uint secondTag, uint thirdTag) = _getTagsForMarket(_market); if ( !riskManager.isMarketForSportOnePositional(firstTag) || (secondTag == TAG_NUMBER_PLAYERS && !riskManager.isMarketForPlayerPorpsOnePositional(thirdTag)) || uint(_position) == 0 ) { oddsToReturn = odds[uint(_position)]; } } } function obtainOddsMulti( address _market, ISportsAMM.Position _position1, ISportsAMM.Position _position2 ) public view returns (uint oddsToReturn1, uint oddsToReturn2) { address theRundownConsumer = sportsAMM.theRundownConsumer(); uint positionsCount = ISportPositionalMarket(_market).optionsCount(); uint[] memory odds = new uint[](ISportPositionalMarket(_market).optionsCount()); odds = ITherundownConsumer(theRundownConsumer).getNormalizedOddsForMarket(_market); if (positionsCount > uint(_position1)) { oddsToReturn1 = odds[uint(_position1)]; } if (positionsCount > uint(_position2)) { oddsToReturn2 = odds[uint(_position2)]; } } function getBalanceOtherSideOnThreePositions( ISportsAMM.Position position, address addressToCheck, address market ) public view returns (uint balanceOfTheOtherSide) { (uint homeBalance, uint awayBalance, uint drawBalance) = getBalanceOfPositionsOnMarket(market, addressToCheck); if (position == ISportsAMM.Position.Home) { balanceOfTheOtherSide = awayBalance < drawBalance ? awayBalance : drawBalance; } else if (position == ISportsAMM.Position.Away) { balanceOfTheOtherSide = homeBalance < drawBalance ? homeBalance : drawBalance; } else { balanceOfTheOtherSide = homeBalance < awayBalance ? homeBalance : awayBalance; } } function getBalanceOfPositionsOnMarket(address market, address addressToCheck) public view returns ( uint homeBalance, uint awayBalance, uint drawBalance ) { (IPosition home, IPosition away, IPosition draw) = ISportPositionalMarket(market).getOptions(); homeBalance = home.getBalanceOf(address(addressToCheck)); awayBalance = away.getBalanceOf(address(addressToCheck)); if (ISportPositionalMarket(market).optionsCount() == 3) { drawBalance = draw.getBalanceOf(address(addressToCheck)); } } function getBalanceOfPositionsOnMarketByPositions( address market, address addressToCheck, ISportsAMM.Position position1, ISportsAMM.Position position2 ) public view returns (uint firstBalance, uint secondBalance) { (uint homeBalance, uint awayBalance, uint drawBalance) = getBalanceOfPositionsOnMarket(market, addressToCheck); firstBalance = position1 == ISportsAMM.Position.Home ? homeBalance : position1 == ISportsAMM.Position.Away ? awayBalance : drawBalance; secondBalance = position2 == ISportsAMM.Position.Home ? homeBalance : position2 == ISportsAMM.Position.Away ? awayBalance : drawBalance; } function balanceOfPositionsOnMarket( address market, ISportsAMM.Position position, address addressToCheck ) public view returns ( uint, uint, uint ) { (IPosition home, IPosition away, ) = ISportPositionalMarket(market).getOptions(); uint balance = position == ISportsAMM.Position.Home ? home.getBalanceOf(addressToCheck) : away.getBalanceOf(addressToCheck); uint balanceOtherSideMax = position == ISportsAMM.Position.Home ? away.getBalanceOf(addressToCheck) : home.getBalanceOf(addressToCheck); uint balanceOtherSideMin = balanceOtherSideMax; if (ISportPositionalMarket(market).optionsCount() == 3) { (uint homeBalance, uint awayBalance, uint drawBalance) = getBalanceOfPositionsOnMarket(market, addressToCheck); if (position == ISportsAMM.Position.Home) { balance = homeBalance; if (awayBalance < drawBalance) { balanceOtherSideMax = drawBalance; balanceOtherSideMin = awayBalance; } else { balanceOtherSideMax = awayBalance; balanceOtherSideMin = drawBalance; } } else if (position == ISportsAMM.Position.Away) { balance = awayBalance; if (homeBalance < drawBalance) { balanceOtherSideMax = drawBalance; balanceOtherSideMin = homeBalance; } else { balanceOtherSideMax = homeBalance; balanceOtherSideMin = drawBalance; } } else if (position == ISportsAMM.Position.Draw) { balance = drawBalance; if (homeBalance < awayBalance) { balanceOtherSideMax = awayBalance; balanceOtherSideMin = homeBalance; } else { balanceOtherSideMax = homeBalance; balanceOtherSideMin = awayBalance; } } } return (balance, balanceOtherSideMax, balanceOtherSideMin); } function balanceOfPositionOnMarket( address market, ISportsAMM.Position position, address addressToCheck ) public view returns (uint) { (IPosition home, IPosition away, IPosition draw) = ISportPositionalMarket(market).getOptions(); uint balance = position == ISportsAMM.Position.Home ? home.getBalanceOf(addressToCheck) : away.getBalanceOf(addressToCheck); if (ISportPositionalMarket(market).optionsCount() == 3 && position != ISportsAMM.Position.Home) { balance = position == ISportsAMM.Position.Away ? away.getBalanceOf(addressToCheck) : draw.getBalanceOf(addressToCheck); } return balance; } function getParentMarketPositions(address market) public view returns ( ISportsAMM.Position position1, ISportsAMM.Position position2, address parentMarket ) { ISportPositionalMarket parentMarketContract = ISportPositionalMarket(market).parentMarket(); (IPosition parentPosition1, IPosition parentPosition2) = ISportPositionalMarket(market).getParentMarketPositions(); (IPosition home, IPosition away, ) = parentMarketContract.getOptions(); position1 = parentPosition1 == home ? ISportsAMM.Position.Home : parentPosition1 == away ? ISportsAMM.Position.Away : ISportsAMM.Position.Draw; position2 = parentPosition2 == home ? ISportsAMM.Position.Home : parentPosition2 == away ? ISportsAMM.Position.Away : ISportsAMM.Position.Draw; parentMarket = address(parentMarketContract); } function getParentMarketPositionAddresses(address market) public view returns (address parentMarketPosition1, address parentMarketPosition2) { (IPosition position1, IPosition position2) = ISportPositionalMarket(market).getParentMarketPositions(); parentMarketPosition1 = address(position1); parentMarketPosition2 = address(position2); } function getBaseOddsForDoubleChance(address market, uint minSupportedOdds) public view returns (uint oddsPosition1, uint oddsPosition2) { (ISportsAMM.Position position1, ISportsAMM.Position position2, address parentMarket) = getParentMarketPositions( market ); oddsPosition1 = obtainOdds(parentMarket, position1); oddsPosition2 = obtainOdds(parentMarket, position2); if (oddsPosition1 > 0 && oddsPosition2 > 0) { oddsPosition1 = oddsPosition1 < minSupportedOdds ? minSupportedOdds : oddsPosition1; oddsPosition2 = oddsPosition2 < minSupportedOdds ? minSupportedOdds : oddsPosition2; } } function getBaseOddsForDoubleChanceSum(address market, uint minSupportedOdds) public view returns (uint sum) { (uint oddsPosition1, uint oddsPosition2) = getBaseOddsForDoubleChance(market, minSupportedOdds); sum = oddsPosition1 + oddsPosition2; } function getBuyPriceImpact(PriceImpactParams memory params) public view returns (int priceImpact) { (uint balancePosition, , uint balanceOtherSide) = balanceOfPositionsOnMarket( params.market, params.position, params.liquidityPool.getMarketPool(params.market) ); bool isTwoPositional = ISportPositionalMarket(params.market).optionsCount() == 2; uint balancePositionAfter = balancePosition > params.amount ? balancePosition - params.amount : 0; uint balanceOtherSideAfter = balancePosition > params.amount ? balanceOtherSide : balanceOtherSide + (params.amount - balancePosition); if (params.amount <= balancePosition) { priceImpact = calculateDiscount( DiscountParams( balancePosition, balanceOtherSide, params.amount, params._availableToBuyFromAMMOtherSide, params.max_spread ) ); } else { if (balancePosition > 0) { uint pricePosition = _obtainOdds(params.market, params.position, params.minSupportedOdds); uint priceOtherPosition = isTwoPositional ? _obtainOdds( params.market, params.position == ISportsAMM.Position.Home ? ISportsAMM.Position.Away : ISportsAMM.Position.Home, params.minSupportedOdds ) : ONE - pricePosition; priceImpact = calculateDiscountFromNegativeToPositive( NegativeDiscountsParams( params.amount, balancePosition, balanceOtherSide, params._availableToBuyFromAMMOtherSide, params._availableToBuyFromAMM, pricePosition, priceOtherPosition, params.max_spread ) ); } else { priceImpact = int( buyPriceImpactImbalancedSkew( params.amount, balanceOtherSide, balancePosition, balanceOtherSideAfter, balancePositionAfter, params._availableToBuyFromAMM, params.max_spread ) ); } } } function _obtainOdds( address _market, ISportsAMM.Position _position, uint minSupportedOdds ) internal view returns (uint) { if (ISportPositionalMarket(_market).isDoubleChance()) { if (_position == ISportsAMM.Position.Home) { return getBaseOddsForDoubleChanceSum(_market, minSupportedOdds); } } return obtainOdds(_market, _position); } function _getTagsForMarket(address _market) internal view returns ( uint tag1, uint tag2, uint tag3 ) { ISportPositionalMarket sportMarket = ISportPositionalMarket(_market); tag1 = sportMarket.tags(0); tag2 = sportMarket.isChild() ? sportMarket.tags(1) : 0; tag3 = sportMarket.isChild() && sportMarket.tags(1) == TAG_NUMBER_PLAYERS ? sportMarket.tags(2) : 0; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; import "../../utils/proxy/solidity-0.8.0/ProxyReentrancyGuard.sol"; import "../../utils/proxy/solidity-0.8.0/ProxyOwned.sol"; import "@openzeppelin/contracts-4.4.1/proxy/Clones.sol"; import "../../interfaces/ISportsAMM.sol"; import "../../interfaces/ISportPositionalMarket.sol"; import "../../interfaces/IStakingThales.sol"; import "./SportAMMLiquidityPoolRound.sol"; contract SportAMMLiquidityPool is Initializable, ProxyOwned, PausableUpgradeable, ProxyReentrancyGuard { /* ========== LIBRARIES ========== */ using SafeERC20Upgradeable for IERC20Upgradeable; struct InitParams { address _owner; ISportsAMM _sportsAmm; IERC20Upgradeable _sUSD; uint _roundLength; uint _maxAllowedDeposit; uint _minDepositAmount; uint _maxAllowedUsers; bool _needsTransformingCollateral; } /* ========== CONSTANTS ========== */ uint private constant HUNDRED = 1e20; uint private constant ONE = 1e18; uint private constant ONE_PERCENT = 1e16; /* ========== STATE VARIABLES ========== */ ISportsAMM public sportsAMM; IERC20Upgradeable public sUSD; bool public started; uint public round; uint public roundLength; uint public firstRoundStartTime; mapping(uint => address) public roundPools; mapping(uint => address[]) public usersPerRound; mapping(uint => mapping(address => bool)) public userInRound; mapping(uint => mapping(address => uint)) public balancesPerRound; mapping(uint => uint) public allocationPerRound; mapping(address => bool) public withdrawalRequested; mapping(uint => address[]) public tradingMarketsPerRound; mapping(uint => mapping(address => bool)) public isTradingMarketInARound; mapping(uint => uint) public profitAndLossPerRound; mapping(uint => uint) public cumulativeProfitAndLoss; uint public maxAllowedDeposit; uint public minDepositAmount; uint public maxAllowedUsers; uint public usersCurrentlyInPool; address public defaultLiquidityProvider; IStakingThales public stakingThales; uint public stakedThalesMultiplier; address public poolRoundMastercopy; mapping(address => bool) public whitelistedDeposits; uint public totalDeposited; bool public onlyWhitelistedStakersAllowed; mapping(address => bool) public whitelistedStakers; bool public needsTransformingCollateral; mapping(uint => mapping(address => bool)) public marketAlreadyExercisedInRound; bool public roundClosingPrepared; uint public usersProcessedInRound; mapping(address => uint) public withdrawalShare; uint public utilizationRate; address public safeBox; uint public safeBoxImpact; /* ========== CONSTRUCTOR ========== */ function initialize(InitParams calldata params) external initializer { setOwner(params._owner); initNonReentrant(); sportsAMM = ISportsAMM(params._sportsAmm); sUSD = params._sUSD; roundLength = params._roundLength; maxAllowedDeposit = params._maxAllowedDeposit; minDepositAmount = params._minDepositAmount; maxAllowedUsers = params._maxAllowedUsers; needsTransformingCollateral = params._needsTransformingCollateral; sUSD.approve(address(sportsAMM), type(uint256).max); } /// @notice Start pool and begin round #1 function start() external onlyOwner { require(!started, "Liquidity pool has already started"); require(allocationPerRound[1] > 0, "can not start with 0 deposits"); firstRoundStartTime = block.timestamp; round = 1; address roundPool = _getOrCreateRoundPool(1); SportAMMLiquidityPoolRound(roundPool).updateRoundTimes(firstRoundStartTime, getRoundEndTime(1)); started = true; emit PoolStarted(); } /// @notice Deposit funds from user into pool for the next round /// @param amount Value to be deposited function deposit(uint amount) external canDeposit(amount) nonReentrant whenNotPaused roundClosingNotPrepared { uint nextRound = round + 1; address roundPool = _getOrCreateRoundPool(nextRound); sUSD.safeTransferFrom(msg.sender, roundPool, amount); if (!whitelistedDeposits[msg.sender]) { require(!onlyWhitelistedStakersAllowed || whitelistedStakers[msg.sender], "Only whitelisted stakers allowed"); require(address(stakingThales) != address(0), "Staking Thales not set"); require( (balancesPerRound[round][msg.sender] + amount + balancesPerRound[nextRound][msg.sender]) <= _transformCollateral((stakingThales.stakedBalanceOf(msg.sender) * stakedThalesMultiplier) / ONE), "Not enough staked THALES" ); } require(msg.sender != defaultLiquidityProvider, "Can't deposit directly as default liquidity provider"); // new user enters the pool if (balancesPerRound[round][msg.sender] == 0 && balancesPerRound[nextRound][msg.sender] == 0) { require(usersCurrentlyInPool < maxAllowedUsers, "Max amount of users reached"); usersPerRound[nextRound].push(msg.sender); usersCurrentlyInPool = usersCurrentlyInPool + 1; } balancesPerRound[nextRound][msg.sender] += amount; allocationPerRound[nextRound] += amount; totalDeposited += amount; if (address(stakingThales) != address(0)) { stakingThales.updateVolume(msg.sender, amount); } emit Deposited(msg.sender, amount, round); } /// @notice get sUSD to mint for buy and store market as trading in the round /// @param market to trade /// @param amountToMint amount to get for mint function commitTrade(address market, uint amountToMint) external nonReentrant whenNotPaused onlyAMM roundClosingNotPrepared { require(started, "Pool has not started"); require(amountToMint > 0, "Can't commit a zero trade"); amountToMint = _transformCollateral(amountToMint); // add 1e-6 due to rounding issue, will be sent back to AMM at the end amountToMint = needsTransformingCollateral ? amountToMint + 1 : amountToMint; uint marketRound = getMarketRound(market); address liquidityPoolRound = _getOrCreateRoundPool(marketRound); if (marketRound == round) { sUSD.safeTransferFrom(liquidityPoolRound, address(sportsAMM), amountToMint); require( sUSD.balanceOf(liquidityPoolRound) >= (allocationPerRound[round] - ((allocationPerRound[round] * utilizationRate) / ONE)), "Amount exceeds available utilization for round" ); } else { uint poolBalance = sUSD.balanceOf(liquidityPoolRound); if (poolBalance >= amountToMint) { sUSD.safeTransferFrom(liquidityPoolRound, address(sportsAMM), amountToMint); } else { uint differenceToLPAsDefault = amountToMint - poolBalance; _depositAsDefault(differenceToLPAsDefault, liquidityPoolRound, marketRound); sUSD.safeTransferFrom(liquidityPoolRound, address(sportsAMM), amountToMint); } } if (!isTradingMarketInARound[marketRound][market]) { tradingMarketsPerRound[marketRound].push(market); isTradingMarketInARound[marketRound][market] = true; } } /// @notice get options that are in the LP into the AMM for the buy tx /// @param market to get options for /// @param optionsAmount to get options for /// @param position to get options for function getOptionsForBuy( address market, uint optionsAmount, ISportsAMM.Position position ) external nonReentrant whenNotPaused onlyAMM roundClosingNotPrepared { if (optionsAmount > 0) { require(started, "Pool has not started"); uint marketRound = getMarketRound(market); address liquidityPoolRound = _getOrCreateRoundPool(marketRound); (IPosition home, IPosition away, IPosition draw) = ISportPositionalMarket(market).getOptions(); IPosition target = position == ISportsAMM.Position.Home ? home : away; if (ISportPositionalMarket(market).optionsCount() > 2 && position != ISportsAMM.Position.Home) { target = position == ISportsAMM.Position.Away ? away : draw; } SportAMMLiquidityPoolRound(liquidityPoolRound).moveOptions( IERC20Upgradeable(address(target)), optionsAmount, address(sportsAMM) ); } } /// @notice get options that are in the LP into the AMM for the buy tx /// @param market to get options for /// @param optionsAmount to get options for /// @param position to get options for function getOptionsForBuyByAddress( address market, uint optionsAmount, address position ) external nonReentrant whenNotPaused onlyAMM roundClosingNotPrepared { if (optionsAmount > 0) { require(started, "Pool has not started"); uint marketRound = getMarketRound(market); address liquidityPoolRound = _getOrCreateRoundPool(marketRound); SportAMMLiquidityPoolRound(liquidityPoolRound).moveOptions( IERC20Upgradeable(position), optionsAmount, address(sportsAMM) ); } } /// @notice Create a round pool by market maturity date if it doesnt already exist /// @param market to use /// @return roundPool the pool for the passed market function getOrCreateMarketPool(address market) external onlyAMM nonReentrant whenNotPaused roundClosingNotPrepared returns (address roundPool) { uint marketRound = getMarketRound(market); roundPool = _getOrCreateRoundPool(marketRound); } /// @notice request withdrawal from the LP function withdrawalRequest() external nonReentrant canWithdraw whenNotPaused roundClosingNotPrepared { if (totalDeposited > balancesPerRound[round][msg.sender]) { totalDeposited -= balancesPerRound[round][msg.sender]; } else { totalDeposited = 0; } usersCurrentlyInPool = usersCurrentlyInPool - 1; withdrawalRequested[msg.sender] = true; emit WithdrawalRequested(msg.sender); } /// @notice request partial withdrawal from the LP. /// @param share the percentage the user is wihdrawing from his total deposit function partialWithdrawalRequest(uint share) external nonReentrant canWithdraw whenNotPaused roundClosingNotPrepared { require(share >= ONE_PERCENT * 10 && share <= ONE_PERCENT * 90, "Share has to be between 10% and 90%"); uint toWithdraw = (balancesPerRound[round][msg.sender] * share) / ONE; if (totalDeposited > toWithdraw) { totalDeposited -= toWithdraw; } else { totalDeposited = 0; } withdrawalRequested[msg.sender] = true; withdrawalShare[msg.sender] = share; emit WithdrawalRequested(msg.sender); } /// @notice Prepare round closing /// excercise options of trading markets and ensure there are no markets left unresolved function prepareRoundClosing() external nonReentrant whenNotPaused roundClosingNotPrepared { require(canCloseCurrentRound(), "Can't close current round"); // excercise market options exerciseMarketsReadyToExercised(); address roundPool = roundPools[round]; // final balance is the final amount of sUSD in the round pool uint currentBalance = sUSD.balanceOf(roundPool); // send profit reserved for SafeBox if positive round if (currentBalance > allocationPerRound[round]) { uint safeBoxAmount = ((currentBalance - allocationPerRound[round]) * safeBoxImpact) / ONE; sUSD.safeTransferFrom(roundPool, safeBox, safeBoxAmount); currentBalance = currentBalance - safeBoxAmount; emit SafeBoxSharePaid(safeBoxImpact, safeBoxAmount); } // calculate PnL // if no allocation for current round if (allocationPerRound[round] == 0) { profitAndLossPerRound[round] = 1; } else { profitAndLossPerRound[round] = (currentBalance * ONE) / allocationPerRound[round]; } roundClosingPrepared = true; emit RoundClosingPrepared(round); } /// @notice Prepare round closing /// excercise options of trading markets and ensure there are no markets left unresolved function processRoundClosingBatch(uint batchSize) external nonReentrant whenNotPaused { require(roundClosingPrepared, "Round closing not prepared"); require(usersProcessedInRound < usersPerRound[round].length, "All users already processed"); require(batchSize > 0, "batchSize has to be greater than 0"); address roundPool = roundPools[round]; uint endCursor = usersProcessedInRound + batchSize; if (endCursor > usersPerRound[round].length) { endCursor = usersPerRound[round].length; } for (uint i = usersProcessedInRound; i < endCursor; i++) { address user = usersPerRound[round][i]; uint balanceAfterCurRound = (balancesPerRound[round][user] * profitAndLossPerRound[round]) / ONE; if (!withdrawalRequested[user] && (profitAndLossPerRound[round] > 0)) { balancesPerRound[round + 1][user] = balancesPerRound[round + 1][user] + balanceAfterCurRound; usersPerRound[round + 1].push(user); if (address(stakingThales) != address(0)) { stakingThales.updateVolume(user, balanceAfterCurRound); } } else { if (withdrawalShare[user] > 0) { uint amountToClaim = (balanceAfterCurRound * withdrawalShare[user]) / ONE; sUSD.safeTransferFrom(roundPool, user, amountToClaim); emit Claimed(user, amountToClaim); withdrawalRequested[user] = false; withdrawalShare[user] = 0; usersPerRound[round + 1].push(user); balancesPerRound[round + 1][user] = balanceAfterCurRound - amountToClaim; } else { balancesPerRound[round + 1][user] = 0; sUSD.safeTransferFrom(roundPool, user, balanceAfterCurRound); withdrawalRequested[user] = false; emit Claimed(user, balanceAfterCurRound); } } usersProcessedInRound = usersProcessedInRound + 1; } emit RoundClosingBatchProcessed(round, batchSize); } /// @notice Close current round and begin next round, /// calculate profit and loss and process withdrawals function closeRound() external nonReentrant whenNotPaused { require(roundClosingPrepared, "Round closing not prepared"); require(usersProcessedInRound == usersPerRound[round].length, "Not all users processed yet"); // set for next round to false roundClosingPrepared = false; address roundPool = roundPools[round]; //always claim for defaultLiquidityProvider if (balancesPerRound[round][defaultLiquidityProvider] > 0) { uint balanceAfterCurRound = (balancesPerRound[round][defaultLiquidityProvider] * profitAndLossPerRound[round]) / ONE; sUSD.safeTransferFrom(roundPool, defaultLiquidityProvider, balanceAfterCurRound); emit Claimed(defaultLiquidityProvider, balanceAfterCurRound); } if (round == 1) { cumulativeProfitAndLoss[round] = profitAndLossPerRound[round]; } else { cumulativeProfitAndLoss[round] = (cumulativeProfitAndLoss[round - 1] * profitAndLossPerRound[round]) / ONE; } // start next round round += 1; //add all carried over sUSD allocationPerRound[round] += sUSD.balanceOf(roundPool); totalDeposited = allocationPerRound[round] - balancesPerRound[round][defaultLiquidityProvider]; address roundPoolNewRound = _getOrCreateRoundPool(round); sUSD.safeTransferFrom(roundPool, roundPoolNewRound, sUSD.balanceOf(roundPool)); usersProcessedInRound = 0; emit RoundClosed(round - 1, profitAndLossPerRound[round - 1]); } /// @notice Iterate all markets in the current round and exercise those ready to be exercised function exerciseMarketsReadyToExercised() public whenNotPaused roundClosingNotPrepared { SportAMMLiquidityPoolRound poolRound = SportAMMLiquidityPoolRound(roundPools[round]); ISportPositionalMarket market; for (uint i = 0; i < tradingMarketsPerRound[round].length; i++) { address marketAddress = tradingMarketsPerRound[round][i]; if (!marketAlreadyExercisedInRound[round][marketAddress]) { market = ISportPositionalMarket(marketAddress); if (market.resolved()) { poolRound.exerciseMarketReadyToExercised(market); marketAlreadyExercisedInRound[round][marketAddress] = true; } } } } /// @notice Exercises markets in a round /// @param batchSize number of markets to be processed function exerciseMarketsReadyToExercisedBatch(uint batchSize) external nonReentrant whenNotPaused roundClosingNotPrepared { require(batchSize > 0, "batchSize has to be greater than 0"); SportAMMLiquidityPoolRound poolRound = SportAMMLiquidityPoolRound(roundPools[round]); uint count = 0; ISportPositionalMarket market; for (uint i = 0; i < tradingMarketsPerRound[round].length; i++) { if (count == batchSize) break; address marketAddress = tradingMarketsPerRound[round][i]; if (!marketAlreadyExercisedInRound[round][marketAddress]) { market = ISportPositionalMarket(marketAddress); if (market.resolved()) { poolRound.exerciseMarketReadyToExercised(market); marketAlreadyExercisedInRound[round][marketAddress] = true; count += 1; } } } } /* ========== VIEWS ========== */ /// @notice whether the user is currently LPing /// @param user to check /// @return isUserInLP whether the user is currently LPing function isUserLPing(address user) external view returns (bool isUserInLP) { isUserInLP = (balancesPerRound[round][user] > 0 || balancesPerRound[round + 1][user] > 0) && (!withdrawalRequested[user] || withdrawalShare[user] > 0); } /// @notice Return the maximum amount the user can deposit now /// @param user address to check /// @return maxDepositForUser the maximum amount the user can deposit in total including already deposited /// @return availableToDepositForUser the maximum amount the user can deposit now /// @return stakedThalesForUser how much THALES the user has staked function getMaxAvailableDepositForUser(address user) external view returns ( uint maxDepositForUser, uint availableToDepositForUser, uint stakedThalesForUser ) { uint nextRound = round + 1; stakedThalesForUser = stakingThales.stakedBalanceOf(user); maxDepositForUser = _transformCollateral((stakedThalesForUser * stakedThalesMultiplier) / ONE); availableToDepositForUser = maxDepositForUser > (balancesPerRound[round][user] + balancesPerRound[nextRound][user]) ? (maxDepositForUser - balancesPerRound[round][user] - balancesPerRound[nextRound][user]) : 0; } //deprecated User can now withdraw at any time /// @notice Return how much the user needs to have staked to withdraw /// @param user address to check /// @return neededStaked how much the user needs to have staked to withdraw function getNeededStakedThalesToWithdrawForUser(address user) external view returns (uint neededStaked) { uint nextRound = round + 1; neededStaked = _reverseTransformCollateral((balancesPerRound[round][user] + balancesPerRound[nextRound][user]) * ONE) / stakedThalesMultiplier; } /// @notice get the pool address for the market /// @param market to check /// @return roundPool the pool address for the market function getMarketPool(address market) external view returns (address roundPool) { roundPool = roundPools[getMarketRound(market)]; } /// @notice Checks if all conditions are met to close the round /// @return bool function canCloseCurrentRound() public view returns (bool) { if (!started || block.timestamp < getRoundEndTime(round)) { return false; } ISportPositionalMarket market; for (uint i = 0; i < tradingMarketsPerRound[round].length; i++) { address marketAddress = tradingMarketsPerRound[round][i]; if (!marketAlreadyExercisedInRound[round][marketAddress]) { market = ISportPositionalMarket(marketAddress); if (!market.resolved()) { return false; } } } return true; } /// @notice Iterate all markets in the current round and return true if at least one can be exercised function hasMarketsReadyToBeExercised() public view returns (bool) { SportAMMLiquidityPoolRound poolRound = SportAMMLiquidityPoolRound(roundPools[round]); ISportPositionalMarket market; for (uint i = 0; i < tradingMarketsPerRound[round].length; i++) { address marketAddress = tradingMarketsPerRound[round][i]; if (!marketAlreadyExercisedInRound[round][marketAddress]) { market = ISportPositionalMarket(marketAddress); if (market.resolved()) { (uint homeBalance, uint awayBalance, uint drawBalance) = market.balancesOf(address(poolRound)); if (homeBalance > 0 || awayBalance > 0 || drawBalance > 0) { return true; } } } } return false; } /// @notice Return multiplied PnLs between rounds /// @param roundA Round number from /// @param roundB Round number to /// @return uint function cumulativePnLBetweenRounds(uint roundA, uint roundB) public view returns (uint) { return (cumulativeProfitAndLoss[roundB] * profitAndLossPerRound[roundA]) / cumulativeProfitAndLoss[roundA]; } /// @notice Return the start time of the passed round /// @param _round number /// @return uint the start time of the given round function getRoundStartTime(uint _round) public view returns (uint) { return firstRoundStartTime + (_round - 1) * roundLength; } /// @notice Return the end time of the passed round /// @param _round number /// @return uint the end time of the given round function getRoundEndTime(uint _round) public view returns (uint) { return firstRoundStartTime + _round * roundLength; } /// @notice Return the round to which a market belongs to /// @param market to get the round for /// @return _round the round which the market belongs to function getMarketRound(address market) public view returns (uint _round) { ISportPositionalMarket marketContract = ISportPositionalMarket(market); (uint maturity, ) = marketContract.times(); if (maturity > firstRoundStartTime) { _round = (maturity - firstRoundStartTime) / roundLength + 1; } else { _round = 1; } } /// @notice Return the count of users in current round /// @return _the count of users in current round function getUsersCountInCurrentRound() external view returns (uint) { return usersPerRound[round].length; } /* ========== INTERNAL FUNCTIONS ========== */ function _transformCollateral(uint value) internal view returns (uint) { if (needsTransformingCollateral) { return value / 1e12; } else { return value; } } function _reverseTransformCollateral(uint value) internal view returns (uint) { if (needsTransformingCollateral) { return value * 1e12; } else { return value; } } function _depositAsDefault( uint amount, address roundPool, uint _round ) internal { require(defaultLiquidityProvider != address(0), "default liquidity provider not set"); sUSD.safeTransferFrom(defaultLiquidityProvider, roundPool, amount); balancesPerRound[_round][defaultLiquidityProvider] += amount; allocationPerRound[_round] += amount; emit Deposited(defaultLiquidityProvider, amount, _round); } function _getOrCreateRoundPool(uint _round) internal returns (address roundPool) { roundPool = roundPools[_round]; if (roundPool == address(0)) { require(poolRoundMastercopy != address(0), "Round pool mastercopy not set"); SportAMMLiquidityPoolRound newRoundPool = SportAMMLiquidityPoolRound(Clones.clone(poolRoundMastercopy)); newRoundPool.initialize(address(this), sUSD, _round, getRoundEndTime(_round - 1), getRoundEndTime(_round)); roundPool = address(newRoundPool); roundPools[_round] = roundPool; emit RoundPoolCreated(_round, roundPool); } } /* ========== SETTERS ========== */ function setPaused(bool _setPausing) external onlyOwner { _setPausing ? _pause() : _unpause(); } /// @notice Set onlyWhitelistedStakersAllowed variable /// @param flagToSet self explanatory function setOnlyWhitelistedStakersAllowed(bool flagToSet) external onlyOwner { onlyWhitelistedStakersAllowed = flagToSet; emit SetOnlyWhitelistedStakersAllowed(flagToSet); } /// @notice Set setNeedsTransformingCollateral variable /// @param _needsTransformingCollateral self explanatory function setNeedsTransformingCollateral(bool _needsTransformingCollateral) external onlyOwner { needsTransformingCollateral = _needsTransformingCollateral; emit SetNeedsTransformingCollateral(_needsTransformingCollateral); } /// @notice Set _poolRoundMastercopy /// @param _poolRoundMastercopy to clone round pools from function setPoolRoundMastercopy(address _poolRoundMastercopy) external onlyOwner { require(_poolRoundMastercopy != address(0), "Can not set a zero address!"); poolRoundMastercopy = _poolRoundMastercopy; emit PoolRoundMastercopyChanged(poolRoundMastercopy); } /// @notice Set _stakedThalesMultiplier /// @param _stakedThalesMultiplier the number of sUSD one can deposit per THALES staked function setStakedThalesMultiplier(uint _stakedThalesMultiplier) external onlyOwner { stakedThalesMultiplier = _stakedThalesMultiplier; emit StakedThalesMultiplierChanged(_stakedThalesMultiplier); } /// @notice Set IStakingThales contract /// @param _stakingThales IStakingThales address function setStakingThales(IStakingThales _stakingThales) external onlyOwner { require(address(_stakingThales) != address(0), "Can not set a zero address!"); stakingThales = _stakingThales; emit StakingThalesChanged(address(_stakingThales)); } /// @notice Set max allowed deposit /// @param _maxAllowedDeposit Deposit value function setMaxAllowedDeposit(uint _maxAllowedDeposit) external onlyOwner { maxAllowedDeposit = _maxAllowedDeposit; emit MaxAllowedDepositChanged(_maxAllowedDeposit); } /// @notice Set min allowed deposit /// @param _minDepositAmount Deposit value function setMinAllowedDeposit(uint _minDepositAmount) external onlyOwner { minDepositAmount = _minDepositAmount; emit MinAllowedDepositChanged(_minDepositAmount); } /// @notice Set _maxAllowedUsers /// @param _maxAllowedUsers Deposit value function setMaxAllowedUsers(uint _maxAllowedUsers) external onlyOwner { maxAllowedUsers = _maxAllowedUsers; emit MaxAllowedUsersChanged(_maxAllowedUsers); } /// @notice Set ThalesAMM contract /// @param _sportAMM ThalesAMM address function setSportAmm(ISportsAMM _sportAMM) external onlyOwner { require(address(_sportAMM) != address(0), "Can not set a zero address!"); sportsAMM = _sportAMM; sUSD.approve(address(sportsAMM), type(uint256).max); emit SportAMMChanged(address(_sportAMM)); } /// @notice Set defaultLiquidityProvider wallet /// @param _defaultLiquidityProvider default liquidity provider function setDefaultLiquidityProvider(address _defaultLiquidityProvider) external onlyOwner { require(_defaultLiquidityProvider != address(0), "Can not set a zero address!"); defaultLiquidityProvider = _defaultLiquidityProvider; emit DefaultLiquidityProviderChanged(_defaultLiquidityProvider); } /// @notice Set length of rounds /// @param _roundLength Length of a round in miliseconds function setRoundLength(uint _roundLength) external onlyOwner { require(!started, "Can't change round length after start"); roundLength = _roundLength; emit RoundLengthChanged(_roundLength); } /// @notice set addresses which can deposit into the AMM bypassing the staking checks /// @param _whitelistedAddresses Addresses to set the whitelist flag for /// @param _flag to set function setWhitelistedAddresses(address[] calldata _whitelistedAddresses, bool _flag) external onlyOwner { require(_whitelistedAddresses.length > 0, "Whitelisted addresses cannot be empty"); for (uint256 index = 0; index < _whitelistedAddresses.length; index++) { // only if current flag is different, if same skip it if (whitelistedDeposits[_whitelistedAddresses[index]] != _flag) { whitelistedDeposits[_whitelistedAddresses[index]] = _flag; emit AddedIntoWhitelist(_whitelistedAddresses[index], _flag); } } } /// @notice set addresses which can deposit into the AMM when only whitelisted stakers are allowed /// @param _whitelistedAddresses Addresses to set the whitelist flag for /// @param _flag to set function setWhitelistedStakerAddresses(address[] calldata _whitelistedAddresses, bool _flag) external onlyOwner { require(_whitelistedAddresses.length > 0, "Whitelisted addresses cannot be empty"); for (uint256 index = 0; index < _whitelistedAddresses.length; index++) { // only if current flag is different, if same skip it if (whitelistedStakers[_whitelistedAddresses[index]] != _flag) { whitelistedStakers[_whitelistedAddresses[index]] = _flag; emit AddedIntoWhitelistStaker(_whitelistedAddresses[index], _flag); } } } /// @notice set utilization rate parameter /// @param _utilizationRate value as percentage function setUtilizationRate(uint _utilizationRate) external onlyOwner { utilizationRate = _utilizationRate; emit UtilizationRateChanged(_utilizationRate); } /// @notice set SafeBox params /// @param _safeBox where to send a profit reserved for protocol from each round /// @param _safeBoxImpact how much is the SafeBox percentage function setSafeBoxParams(address _safeBox, uint _safeBoxImpact) external onlyOwner { safeBox = _safeBox; safeBoxImpact = _safeBoxImpact; emit SetSafeBoxParams(_safeBox, _safeBoxImpact); } /* ========== MODIFIERS ========== */ modifier canDeposit(uint amount) { require(!withdrawalRequested[msg.sender], "Withdrawal is requested, cannot deposit"); require(totalDeposited + amount <= maxAllowedDeposit, "Deposit amount exceeds AMM LP cap"); if (balancesPerRound[round][msg.sender] == 0 && balancesPerRound[round + 1][msg.sender] == 0) { require(amount >= minDepositAmount, "Amount less than minDepositAmount"); } _; } modifier canWithdraw() { require(started, "Pool has not started"); require(!withdrawalRequested[msg.sender], "Withdrawal already requested"); require(balancesPerRound[round][msg.sender] > 0, "Nothing to withdraw"); require(balancesPerRound[round + 1][msg.sender] == 0, "Can't withdraw as you already deposited for next round"); _; } modifier onlyAMM() { require(msg.sender == address(sportsAMM), "only the AMM may perform these methods"); _; } modifier roundClosingNotPrepared() { require(!roundClosingPrepared, "Not allowed during roundClosingPrepared"); _; } /* ========== EVENTS ========== */ event PoolStarted(); event Deposited(address user, uint amount, uint round); event WithdrawalRequested(address user); event RoundClosed(uint round, uint roundPnL); event Claimed(address user, uint amount); event RoundPoolCreated(uint _round, address roundPool); event PoolRoundMastercopyChanged(address newMastercopy); event StakedThalesMultiplierChanged(uint _stakedThalesMultiplier); event StakingThalesChanged(address stakingThales); event MaxAllowedDepositChanged(uint maxAllowedDeposit); event MinAllowedDepositChanged(uint minAllowedDeposit); event MaxAllowedUsersChanged(uint MaxAllowedUsersChanged); event SportAMMChanged(address sportAMM); event DefaultLiquidityProviderChanged(address newProvider); event AddedIntoWhitelist(address _whitelistAddress, bool _flag); event AddedIntoWhitelistStaker(address _whitelistAddress, bool _flag); event RoundLengthChanged(uint roundLength); event SetOnlyWhitelistedStakersAllowed(bool flagToSet); event RoundClosingPrepared(uint round); event RoundClosingBatchProcessed(uint round, uint batchSize); event UtilizationRateChanged(uint utilizationRate); event SetSafeBoxParams(address safeBox, uint safeBoxImpact); event SafeBoxSharePaid(uint safeBoxShare, uint safeBoxAmount); event SetNeedsTransformingCollateral(bool needs); }
// 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); } } } }
// 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; }
// 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; }
// 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); }
// 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; }
// 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); }
// 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)); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; import "../../interfaces/ISportPositionalMarket.sol"; import "./SportAMMLiquidityPool.sol"; contract SportAMMLiquidityPoolRound { /* ========== LIBRARIES ========== */ using SafeERC20Upgradeable for IERC20Upgradeable; /* ========== STATE VARIABLES ========== */ SportAMMLiquidityPool public liquidityPool; IERC20Upgradeable public sUSD; uint public round; uint public roundStartTime; uint public roundEndTime; /* ========== CONSTRUCTOR ========== */ bool public initialized; function initialize( address _liquidityPool, IERC20Upgradeable _sUSD, uint _round, uint _roundStartTime, uint _roundEndTime ) external { require(!initialized, "Already initialized"); initialized = true; liquidityPool = SportAMMLiquidityPool(_liquidityPool); sUSD = _sUSD; round = _round; roundStartTime = _roundStartTime; roundEndTime = _roundEndTime; sUSD.approve(_liquidityPool, type(uint256).max); } function updateRoundTimes(uint _roundStartTime, uint _roundEndTime) external onlyLiquidityPool { roundStartTime = _roundStartTime; roundEndTime = _roundEndTime; emit RoundTimesUpdated(_roundStartTime, _roundEndTime); } function exerciseMarketReadyToExercised(ISportPositionalMarket market) external onlyLiquidityPool { if (market.resolved()) { (uint homeBalance, uint awayBalance, uint drawBalance) = market.balancesOf(address(this)); if (homeBalance > 0 || awayBalance > 0 || drawBalance > 0) { market.exerciseOptions(); } } } function moveOptions( IERC20Upgradeable option, uint optionsAmount, address destination ) external onlyLiquidityPool { option.safeTransfer(destination, optionsAmount); } modifier onlyLiquidityPool() { require(msg.sender == address(liquidityPool), "only the Pool manager may perform these methods"); _; } event RoundTimesUpdated(uint _roundStartTime, uint _roundEndTime); }
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_safeBox","type":"address"},{"indexed":false,"internalType":"contract IERC20Upgradeable","name":"_sUSD","type":"address"},{"indexed":false,"internalType":"address","name":"_theRundownConsumer","type":"address"},{"indexed":false,"internalType":"contract IStakingThales","name":"_stakingThales","type":"address"},{"indexed":false,"internalType":"address","name":"_referrals","type":"address"},{"indexed":false,"internalType":"address","name":"_parlayAMM","type":"address"},{"indexed":false,"internalType":"address","name":"_wrapper","type":"address"},{"indexed":false,"internalType":"address","name":"_lp","type":"address"},{"indexed":false,"internalType":"address","name":"_riskManager","type":"address"}],"name":"AddressesUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"buyer","type":"address"},{"indexed":false,"internalType":"address","name":"market","type":"address"},{"indexed":false,"internalType":"enum ISportsAMM.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":"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":"uint256","name":"_minimalTimeLeftToMaturity","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_minSpread","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_maxSpread","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_minSupportedOdds","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_maxSupportedOdds","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_safeBoxImpact","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_referrerFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"threshold","type":"uint256"}],"name":"ParametersUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","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":"_tag1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_tag2","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_spread","type":"uint256"}],"name":"SetMinSpreadPerSport","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_sport","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_minSupportedOddsPerSport","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_maxSpreadPerSport","type":"uint256"}],"name":"SetMinSupportedOddsAndMaxSpreadPerSport","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_manager","type":"address"}],"name":"SetSportsPositionalMarketManager","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"TAG_NUMBER_PLAYERS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"apexConsumer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"enum ISportsAMM.Position","name":"position","type":"uint8"}],"name":"availableToBuyFromAMM","outputs":[{"internalType":"uint256","name":"_available","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"enum ISportsAMM.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":"address","name":"market","type":"address"},{"internalType":"enum ISportsAMM.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"}],"name":"buyFromAMMWithDifferentCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"enum ISportsAMM.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":"address","name":"market","type":"address"},{"internalType":"enum ISportsAMM.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":"address","name":"market","type":"address"},{"internalType":"enum ISportsAMM.Position","name":"position","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"buyFromAmmQuote","outputs":[{"internalType":"uint256","name":"_quote","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"enum ISportsAMM.Position","name":"position","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"buyFromAmmQuoteForParlayAMM","outputs":[{"internalType":"uint256","name":"_quote","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"},{"internalType":"enum ISportsAMM.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":"market","type":"address"},{"internalType":"enum ISportsAMM.Position","name":"position","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"buyPriceImpact","outputs":[{"internalType":"int256","name":"impact","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"capPerMarket","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"capPerSport","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"capPerSportAndChild","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"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":[],"name":"defaultCapPerGame","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"bool","name":"isSell","type":"bool"}],"name":"getMarketDefaultOdds","outputs":[{"internalType":"uint256[]","name":"odds","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initNonReentrant","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"contract IERC20Upgradeable","name":"_sUSD","type":"address"},{"internalType":"uint256","name":"_min_spread","type":"uint256"},{"internalType":"uint256","name":"_max_spread","type":"uint256"},{"internalType":"uint256","name":"_minimalTimeLeftToMaturity","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"isMarketForSportOnePositional","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"}],"name":"isMarketInAMMTrading","outputs":[{"internalType":"bool","name":"isTrading","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liquidityPool","outputs":[{"internalType":"contract SportAMMLiquidityPool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxAllowedPegSlippagePercentage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"maxSpreadPerSport","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSupportedOdds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"max_spread","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"minSpreadPerSport","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minSupportedOdds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"minSupportedOddsPerSport","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"min_spread","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"min_spreadPerAddress","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minimalTimeLeftToMaturity","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":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"enum ISportsAMM.Position","name":"_position","type":"uint8"}],"name":"obtainOdds","outputs":[{"internalType":"uint256","name":"oddsToReturn","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"parlayAMM","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":"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":[],"name":"riskManager","outputs":[{"internalType":"contract ISportAMMRiskManager","name":"","type":"address"}],"stateMutability":"view","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":[{"internalType":"address","name":"","type":"address"}],"name":"safeBoxFeePerAddress","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"safeBoxImpact","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_safeBox","type":"address"},{"internalType":"contract IERC20Upgradeable","name":"_sUSD","type":"address"},{"internalType":"address","name":"_theRundownConsumer","type":"address"},{"internalType":"contract IStakingThales","name":"_stakingThales","type":"address"},{"internalType":"address","name":"_referrals","type":"address"},{"internalType":"address","name":"_parlayAMM","type":"address"},{"internalType":"address","name":"_wrapper","type":"address"},{"internalType":"address","name":"_lp","type":"address"},{"internalType":"address","name":"_riskManager","type":"address"}],"name":"setAddresses","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract SportsAMMUtils","name":"_ammUtils","type":"address"}],"name":"setAmmUtils","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_curveSUSD","type":"address"},{"internalType":"address","name":"_dai","type":"address"},{"internalType":"address","name":"_usdc","type":"address"},{"internalType":"address","name":"_usdt","type":"address"},{"internalType":"bool","name":"_curveOnrampEnabled","type":"bool"},{"internalType":"uint256","name":"_maxAllowedPegSlippagePercentage","type":"uint256"}],"name":"setCurveSUSD","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tag1","type":"uint256"},{"internalType":"uint256","name":"_tag2","type":"uint256"},{"internalType":"uint256","name":"_minSpread","type":"uint256"}],"name":"setMinSpreadPerSport","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_sportID","type":"uint256"},{"internalType":"uint256","name":"_minSupportedOdds","type":"uint256"},{"internalType":"uint256","name":"_maxSpreadPerSport","type":"uint256"}],"name":"setMinSupportedOddsAndMaxSpreadPerSportPerSport","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_minimalTimeLeftToMaturity","type":"uint256"},{"internalType":"uint256","name":"_minSpread","type":"uint256"},{"internalType":"uint256","name":"_maxSpread","type":"uint256"},{"internalType":"uint256","name":"_minSupportedOdds","type":"uint256"},{"internalType":"uint256","name":"_maxSupportedOdds","type":"uint256"},{"internalType":"uint256","name":"_safeBoxImpact","type":"uint256"},{"internalType":"uint256","name":"_referrerFee","type":"uint256"},{"internalType":"uint256","name":"_threshold","type":"uint256"}],"name":"setParameters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_setPausing","type":"bool"}],"name":"setPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"},{"internalType":"uint256","name":"newSBFee","type":"uint256"},{"internalType":"uint256","name":"newMSFee","type":"uint256"}],"name":"setSafeBoxFeeAndMinSpreadPerAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_manager","type":"address"}],"name":"setSportsPositionalMarketManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"spentOnGame","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"spentOnParent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sportAmmUtils","outputs":[{"internalType":"contract SportsAMMUtils","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stakingThales","outputs":[{"internalType":"contract IStakingThales","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"theRundownConsumer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"thresholdForOddsUpdate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"proxyAddress","type":"address"}],"name":"transferOwnershipAtInit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"address payable","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"all","type":"bool"}],"name":"transferTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"updateParlayVolume","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"},{"inputs":[],"name":"wrapper","outputs":[{"internalType":"contract ITherundownConsumerWrapper","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
608060405234801561001057600080fd5b50615e3080620000216000396000f3fe608060405234801561001057600080fd5b506004361061041d5760003560e01c806379ba50971161022b578063bf46c0b411610130578063df8974d0116100b8578063ec933f8311610087578063ec933f831461098f578063efc15251146109a2578063f4b9fa75146109b5578063f88b7571146109c8578063fd8a8cc6146109db57600080fd5b8063df8974d014610962578063e4d34a031461096b578063e88698bf1461097e578063ebc797721461098757600080fd5b8063d333ca19116100ff578063d333ca19146108f8578063d3c4297c1461090b578063d3dc75391461091e578063d4a2641b14610931578063d69fb6681461095957600080fd5b8063bf46c0b41461089f578063c3b83f5f146108b2578063cbeb9d66146108c5578063d13f90b4146108e557600080fd5b80639324cac7116101b3578063ac210cc711610182578063ac210cc71461081b578063b24ef6381461082e578063b4cb26de14610841578063bb96af651461086c578063be2f12271461087f57600080fd5b80639324cac7146107ca5780639f916c9f146107e2578063a5bf660d146107f5578063a89ea2c01461080857600080fd5b80638a7c84e5116101fa5780638a7c84e5146107235780638afdf2d8146107435780638da5cb5b146107635780638dfd117e1461077c57806392294b0a1461079f57600080fd5b806379ba5097146106ec5780637b4626bd146106f45780637d550e05146106fd5780638875eb841461071057600080fd5b8063443a4077116103315780635bbd7353116102b9578063662720441161028857806366272044146106a1578063665a11ca146106b45780636aaa81b6146106c75780636cc5a6ff146106d05780636e88a7bd146106e357600080fd5b80635bbd7353146106435780635c975abb146106565780635d6a738c1461066157806365f567721461068157600080fd5b80634a50215e116103005780634a50215e146105e457806350d851a1146105f75780635266d4881461060a57806353a47bb71461061d5780635727a0f31461063057600080fd5b8063443a40771461059857806347842663146105ab578063481c6a75146105be57806348663e95146105d157600080fd5b8063270e13ef116103b4578063316425c311610383578063316425c314610557578063343d372f1461056057806334ba3c71146105695780633e413bee1461057c578063429386c41461058f57600080fd5b8063270e13ef146104f05780632909f51a146105035780632972e8ab1461050c5780632f48ab7d1461052c57600080fd5b806316c38b3c116103f057806316c38b3c146104795780631a930f761461048c5780631fbb38e8146104ac578063245afa47146104d057600080fd5b806309b03964146104225780630fabf2061461044857806313af4035146104515780631627540c14610466575b600080fd5b610435610430366004615543565b6109ee565b6040519081526020015b60405180910390f35b61043560805481565b61046461045f3660046152f5565b610a4d565b005b6104646104743660046152f5565b610b8d565b6104646104873660046157e4565b610be3565b61043561049a3660046152f5565b607f6020526000908152604090205481565b6077546104c090600160a01b900460ff1681565b604051901515815260200161043f565b6104356104de3660046152f5565b608b6020526000908152604090205481565b6104356104fe366004615543565b610c03565b610435607c5481565b61043561051a3660046152f5565b60836020526000908152604090205481565b60765461053f906001600160a01b031681565b6040516001600160a01b03909116815260200161043f565b610435606b5481565b61043561271a81565b610464610577366004615964565b610c66565b60755461053f906001600160a01b031681565b61043560695481565b6104646105a63660046156e7565b610d02565b608a5461053f906001600160a01b031681565b60685461053f906001600160a01b031681565b606e5461053f906001600160a01b031681565b6104646105f2366004615746565b610dc7565b610435610605366004615516565b610f60565b610464610618366004615712565b610f6c565b60015461053f906001600160a01b031681565b6104c061063e3660046152f5565b610f9c565b607b5461053f906001600160a01b031681565b60345460ff166104c0565b61043561066f3660046158b0565b607d6020526000908152604090205481565b61043561068f3660046152f5565b60826020526000908152604090205481565b6104646106af36600461540b565b6110b3565b60855461053f906001600160a01b031681565b610435606a5481565b6104646106de36600461566d565b6111d6565b61043560795481565b6104646112c2565b61043560725481565b607a5461053f906001600160a01b031681565b61046461071e3660046155d5565b6113bf565b6104356107313660046152f5565b606d6020526000908152604090205481565b6107566107513660046153de565b611485565b60405161043f9190615b2c565b60005461053f906201000090046001600160a01b031681565b6104c061078a3660046158b0565b60876020526000908152604090205460ff1681565b6104356107ad3660046158c8565b608660209081526000928352604080842090915290825290205481565b60675461053f9061010090046001600160a01b031681565b6104646107f0366004615607565b6115db565b60745461053f906001600160a01b031681565b61046461081636600461590c565b61171f565b60815461053f906001600160a01b031681565b607e5461053f906001600160a01b031681565b61043561084f3660046158c8565b608460209081526000928352604080842090915290825290205481565b606f5461053f906001600160a01b031681565b61043561088d3660046158b0565b60896020526000908152604090205481565b6104356108ad366004615543565b611788565b6104646108c03660046152f5565b611945565b6104356108d33660046158b0565b60886020526000908152604090205481565b6104646108f33660046154c6565b611a5e565b6104646109063660046152f5565b611b5b565b610464610919366004615366565b611b85565b60785461053f906001600160a01b031681565b61094461093f366004615583565b611d85565b6040805192835260208301919091520161043f565b61043560705481565b610435606c5481565b61046461097936600461590c565b611e9e565b61043560735481565b610464611f00565b61046461099d366004615607565b611f5e565b6104356109b0366004615516565b611faa565b60775461053f906001600160a01b031681565b6104646109d63660046152f5565b611fed565b60715461053f906001600160a01b031681565b6000806109fb858561216a565b90506000610a0886612326565b9050600082118015610a1957508082105b610a235781610a25565b805b9150610a438686868560008060006001610a3e8f612366565b61253e565b9695505050505050565b6001600160a01b038116610aa85760405162461bcd60e51b815260206004820152601960248201527f4f776e657220616464726573732063616e6e6f7420626520300000000000000060448201526064015b60405180910390fd5b600154600160a01b900460ff1615610b145760405162461bcd60e51b815260206004820152602960248201527f416c726561647920696e697469616c697a65642c20757365206e6f6d696e617460448201526832a732bba7bbb732b960b91b6064820152608401610a9f565b6001805460ff60a01b1916600160a01b179055600080546001600160a01b03831662010000810262010000600160b01b03199092169190911782556040805192835260208301919091527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c91015b60405180910390a150565b610b9561257d565b600180546001600160a01b0319166001600160a01b0383169081179091556040519081527f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce2290602001610b82565b610beb61257d565b80610bfb57610bf86125f7565b50565b610bf861268a565b6000610c0e84610f9c565b15610c5f576000610c1f858561216a565b90508015610c5d576000610c3286612326565b9050808210610c415781610c43565b805b9150610a43868686856070546000806001610a3e8f612366565b505b9392505050565b610c6e61257d565b606c889055606a879055606b86905560728590556073849055607083905560798290556080818155604080518a8152602081018a90528082018990526060810188905291820186905260a0820185905260c0820184905260e08201839052517f3a2276994eb7c279297bcbc22f9e4dda9af91c054220b647ffa9dd9a72d46d62918190036101000190a15050505050505050565b607a546001600160a01b03163314610d4d5760405162461bcd60e51b815260206004820152600e60248201526d24b73b30b634b21031b0b63632b960911b6044820152606401610a9f565b6071546001600160a01b031615610dc3576071546040516302c7739b60e01b81526001600160a01b03909116906302c7739b90610d909085908590600401615aef565b600060405180830381600087803b158015610daa57600080fd5b505af1158015610dbe573d6000803e3d6000fd5b505050505b5050565b610dcf61257d565b83610e1c5760405162461bcd60e51b815260206004820152601a60248201527f746f6b656e732061727261792063616e7420626520656d7074790000000000006044820152606401610a9f565b60005b84811015610dbe578115610f2957610f2484878784818110610e5157634e487b7160e01b600052603260045260246000fd5b9050602002016020810190610e6691906152f5565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a082319060240160206040518083038186803b158015610ea757600080fd5b505afa158015610ebb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610edf9190615898565b888885818110610eff57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190610f1491906152f5565b6001600160a01b031691906126e2565b610f4e565b610f4e8484888885818110610eff57634e487b7160e01b600052603260045260246000fd5b80610f5881615d6f565b915050610e1f565b6000610c5f838361216a565b610f7461257d565b6001600160a01b03909216600090815260826020908152604080832093909355608390522055565b606854604051633761c52760e11b81526001600160a01b0383811660048301526000921690636ec38a4e9060240160206040518083038186803b158015610fe257600080fd5b505afa158015610ff6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061101a9190615800565b156110ae576000826001600160a01b0316639e3b34bf6040518163ffffffff1660e01b8152600401604080518083038186803b15801561105957600080fd5b505afa15801561106d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061109191906158e9565b5090504281106110ac57606c546110a84283615d2c565b1191505b505b919050565b6110bb61257d565b606e80546001600160a01b038b81166001600160a01b03199283168117909355606780548c8316610100818102610100600160a81b031990931692909217909255606f80548d85169086168117909155607180548d86169087168117909155607880548d87169088168117909155607a80548d88169089168117909155608180548d8916908a168117909155608580548d8a16908b168117909155608a8054998d1699909a168917909955604080519a8b5260208b0197909752898701949094526060890192909252608088015260a087015260c086015260e085019390935291830152517fdcb493c60570bc553de543bccde79755ef6ea8eb71e9cd8a77fcbc84d24766f0918190036101200190a1505050505050505050565b6001606660008282546111e99190615cb3565b909155505060665460345460ff16156112145760405162461bcd60e51b8152600401610a9f90615ba3565b6001600160a01b038216156112895760785460405163bbddaca360e01b81526001600160a01b0384811660048301523360248301529091169063bbddaca390604401600060405180830381600087803b15801561127057600080fd5b505af1158015611284573d6000803e3d6000fd5b505050505b61129788888888888861273d565b60665481146112b85760405162461bcd60e51b8152600401610a9f90615bcd565b5050505050505050565b6001546001600160a01b0316331461133a5760405162461bcd60e51b815260206004820152603560248201527f596f75206d757374206265206e6f6d696e61746564206265666f726520796f7560448201527402063616e20616363657074206f776e65727368697605c1b6064820152608401610a9f565b60005460015460408051620100009093046001600160a01b03908116845290911660208301527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c910160405180910390a1600180546000805462010000600160b01b0319166001600160a01b03831662010000021790556001600160a01b0319169055565b6001606660008282546113d29190615cb3565b909155505060665460345460ff16156113fd5760405162461bcd60e51b8152600401610a9f90615ba3565b6114646040518060e00160405280886001600160a01b0316815260200187600281111561143a57634e487b7160e01b600052602160045260246000fd5b81526020018681526020018581526020018481526020016001151581526020016000815250612a16565b6066548114610dbe5760405162461bcd60e51b8152600401610a9f90615bcd565b6060826001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b1580156114c057600080fd5b505afa1580156114d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114f89190615898565b67ffffffffffffffff81111561151e57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015611547578160200160208202803683370190505b50905061155383610f9c565b156115d55760005b81518110156115d3576115968482600281111561158857634e487b7160e01b600052602160045260246000fd5b670de0b6b3a7640000610c03565b8282815181106115b657634e487b7160e01b600052603260045260246000fd5b6020908102919091010152806115cb81615d6f565b91505061155b565b505b92915050565b6001606660008282546115ee9190615cb3565b909155505060665460345460ff16156116195760405162461bcd60e51b8152600401610a9f90615ba3565b6001600160a01b0382161561168e5760785460405163bbddaca360e01b81526001600160a01b0384811660048301523360248301529091169063bbddaca390604401600060405180830381600087803b15801561167557600080fd5b505af1158015611689573d6000803e3d6000fd5b505050505b6116f56040518060e00160405280896001600160a01b031681526020018860028111156116cb57634e487b7160e01b600052602160045260246000fd5b81526020018781526020018681526020018581526020016001151581526020016000815250612a16565b60665481146117165760405162461bcd60e51b8152600401610a9f90615bcd565b50505050505050565b61172761257d565b600083815260866020908152604080832085845282529182902083905581518581529081018490529081018290527f7f7dca69aeedcc1ad02bd2c02f9fd876840091fb7d939d6dfafeb9cd308ba061906060015b60405180910390a1505050565b60685460405163352feab360e11b81526001600160a01b0385811660048301526000921690636a5fd5669060240160206040518083038186803b1580156117ce57600080fd5b505afa1580156117e2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118069190615800565b156118fe57600083600281111561182d57634e487b7160e01b600052602160045260246000fd5b14156118f957607e5460405163a4d682dd60e01b81526001600160a01b038681166004830152600092839283929091169063a4d682dd9060240160606040518083038186803b15801561187f57600080fd5b505afa158015611893573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118b79190615868565b92509250925060006118ca828588611788565b905060006118d9838589611788565b905060026118e78284615c72565b6118f19190615ccb565b955050505050505b610c5f565b600061190a8585611faa565b9050600061191886866136c2565b905060008411801561192a5750818411155b1561193c57610a4386868685856137a3565b50509392505050565b61194d61257d565b6001600160a01b0381166119955760405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b6044820152606401610a9f565b600154600160a81b900460ff16156119e55760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481d1c985b9cd9995c9c9959606a1b6044820152606401610a9f565b600080546001600160a01b038381166201000081810262010000600160b01b031990941693909317938490556001805460ff60a81b1916600160a81b1790556040805193909404909116825260208201527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9101610b82565b600054610100900460ff16611a795760005460ff1615611a7d565b303b155b611ae05760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610a9f565b600054610100900460ff16158015611b02576000805461ffff19166101011790555b611b0b86610a4d565b611b13611f00565b60678054610100600160a81b0319166101006001600160a01b03881602179055606a849055606b839055606c8290558015610dbe576000805461ff0019169055505050505050565b611b6361257d565b607e80546001600160a01b0319166001600160a01b0392909216919091179055565b611b8d61257d565b607480546001600160a01b038089166001600160a01b03199283161790925560778054888416908316811790915560758054888516908416179055607680549387169390921692909217905560405163095ea7b360e01b815263095ea7b390611bfe90899060001990600401615aef565b602060405180830381600087803b158015611c1857600080fd5b505af1158015611c2c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c509190615800565b5060755460405163095ea7b360e01b81526001600160a01b039091169063095ea7b390611c8590899060001990600401615aef565b602060405180830381600087803b158015611c9f57600080fd5b505af1158015611cb3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cd79190615800565b5060765460405163095ea7b360e01b81526001600160a01b039091169063095ea7b390611d0c90899060001990600401615aef565b602060405180830381600087803b158015611d2657600080fd5b505af1158015611d3a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d5e9190615800565b5060778054921515600160a01b0260ff60a01b1990931692909217909155607c5550505050565b6000806000611d93846138ab565b9050600081600f0b138015611db15750607754600160a01b900460ff165b15611e9457611dc1878787610c03565b9150670de0b6b3a7640000611dde6005662386f26fc10000615cf9565b611df090670de0b6b3a7640000615cb3565b6074546040516307211ef760e01b815260006004820152600f85900b6024820152604481018690526001600160a01b03909116906307211ef79060640160206040518083038186803b158015611e4557600080fd5b505afa158015611e59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e7d9190615898565b611e879190615d0d565b611e919190615cf9565b92505b5094509492505050565b611ea661257d565b6000838152608860209081526040808320859055608982529182902083905581518581529081018490529081018290527f991710c3fe78c1915a791ed2dceeaac2a00c464dc95b92b8e040bb02b9da48e59060600161177b565b60675460ff1615611f495760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b6044820152606401610a9f565b6067805460ff19166001908117909155606655565b600160666000828254611f719190615cb3565b909155505060665460345460ff1615611f9c5760405162461bcd60e51b8152600401610a9f90615ba3565b6116f587878787878761273d565b6000611fb583610f9c565b156115d5576000611fc6848461216a565b905080156115d357611fe5848483600080611fe08a612366565b613900565b949350505050565b611ff561257d565b6001600160a01b0381161561208f5760675460405163095ea7b360e01b81526101009091046001600160a01b03169063095ea7b39061203b908490600090600401615aef565b602060405180830381600087803b15801561205557600080fd5b505af1158015612069573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061208d9190615800565b505b606880546001600160a01b0319166001600160a01b0383811691821790925560675460405163095ea7b360e01b81526101009091049092169163095ea7b3916120de9160001990600401615aef565b602060405180830381600087803b1580156120f857600080fd5b505af115801561210c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121309190615800565b506040516001600160a01b03821681527f1f728ba0a73bcdf17f9e0f260b7db049043dfa6b907980f715e30767d36bc70690602001610b82565b60685460405163352feab360e11b81526001600160a01b0384811660048301526000921690636a5fd5669060240160206040518083038186803b1580156121b057600080fd5b505afa1580156121c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121e89190615800565b156122a457600082600281111561220f57634e487b7160e01b600052602160045260246000fd5b14156122a457607e546001600160a01b031663a119612d8461223081612326565b6040518363ffffffff1660e01b815260040161224d929190615aef565b60206040518083038186803b15801561226557600080fd5b505afa158015612279573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061229d9190615898565b90506115d5565b607e546040516350d851a160e01b81526001600160a01b03909116906350d851a1906122d69086908690600401615a78565b60206040518083038186803b1580156122ee57600080fd5b505afa158015612302573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c5f9190615898565b600080612332836139b8565b5060008181526088602052604090205490915061235157607254610c5f565b60009081526088602052604090205492915050565b612392604080516080810190915260008082526020820190815260200160008152600060209091015290565b60685460405163352feab360e11b81526001600160a01b03848116600483015290911690636a5fd5669060240160206040518083038186803b1580156123d757600080fd5b505afa1580156123eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061240f9190615800565b61243f57604080516080810190915260008082526020820190815260200160018152600060209091015292915050565b607e5460405163a4d682dd60e01b81526001600160a01b038481166004830152600092839283929091169063a4d682dd9060240160606040518083038186803b15801561248b57600080fd5b505afa15801561249f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124c39190615868565b92509250925060405180608001604052806001151581526020018460028111156124fd57634e487b7160e01b600052602160045260246000fd5b815260200183600281111561252257634e487b7160e01b600052602160045260246000fd5b8152602001826001600160a01b03168152509350505050919050565b80516000901561255d576125568a8a8a898787613b35565b9050612570565b61256d8a8a8a8a8a8a8a8a613c6e565b90505b9998505050505050505050565b6000546201000090046001600160a01b031633146125f55760405162461bcd60e51b815260206004820152602f60248201527f4f6e6c792074686520636f6e7472616374206f776e6572206d6179207065726660448201526e37b936903a3434b99030b1ba34b7b760891b6064820152608401610a9f565b565b60345460ff166126405760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610a9f565b6034805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b60345460ff16156126ad5760405162461bcd60e51b8152600401610a9f90615ba3565b6034805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861266d3390565b6127388363a9059cbb60e01b8484604051602401612701929190615aef565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613e13565b505050565b6000612748826138ab565b9050600081600f0b1380156127665750607754600160a01b900460ff165b6127ab5760405162461bcd60e51b81526020600482015260166024820152751d5b9cdd5c1c1bdc9d19590818dbdb1b185d195c985b60521b6044820152606401610a9f565b6000806127ba89898987611d85565b60755491935091506000906001600160a01b03868116911614806127eb57506076546001600160a01b038681169116145b6127f55782612804565b6128048364e8d4a51000615d0d565b90506000607c5411801561284a5750670de0b6b3a7640000607c54670de0b6b3a76400006128329190615d2c565b61283c9084615d0d565b6128469190615cf9565b8110155b6128895760405162461bcd60e51b815260206004820152601060248201526f4d61782070656720736c69707061676560801b6044820152606401610a9f565b61289b86670de0b6b3a7640000615cb3565b876128ae670de0b6b3a764000086615d0d565b6128b89190615cf9565b11156128f65760405162461bcd60e51b815260206004820152600d60248201526c4869676820736c69707061676560981b6044820152606401610a9f565b8461290c6001600160a01b038216333087613ee5565b607454604051635320bf6b60e11b8152600f87900b60048201526000602482015260448101869052606481018590526001600160a01b039091169063a6417ed690608401602060405180830381600087803b15801561296a57600080fd5b505af115801561297e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129a29190615898565b50612a096040518060e001604052808d6001600160a01b031681526020018c60028111156129e057634e487b7160e01b600052602160045260246000fd5b81526020018b815260200185815260200189815260200160001515815260200185815250612a16565b5050505050505050505050565b612a2881600001518260200151613f23565b6000612a378260000151612366565b80519091501580612a6b5750600082602001516002811115612a6957634e487b7160e01b600052602160045260246000fd5b145b612aa55760405162461bcd60e51b815260206004820152600b60248201526a496e76616c696420706f7360a81b6044820152606401610a9f565b6000612abe836000015184602001518460000151614037565b905060008111612aff5760405162461bcd60e51b815260206004820152600c60248201526b4e6f2062617365206f64647360a01b6044820152606401610a9f565b6000612b0e8460000151612326565b9050808210612b1d5781612b1f565b805b607e548551602087015160855460405163c2edfc7360e01b81526001600160a01b0380851660048301529597506000959485169463e468265c949392169063c2edfc739060240160206040518083038186803b158015612b7e57600080fd5b505afa158015612b92573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bb69190615311565b6040518463ffffffff1660e01b8152600401612bd493929190615a95565b60206040518083038186803b158015612bec57600080fd5b505afa158015612c00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c249190615898565b90506000612c3f86600001518760200151868560018a613900565b905067016345785d8a00008660400151118015612c60575080866040015111155b612ca15760405162461bcd60e51b815260206004820152601260248201527104c6f77206c6971756964697479207c7c20360741b6044820152606401610a9f565b8560a0015115612d7857612cd286600001518760200151886040015187612cc733614150565b86600160008d61253e565b60c08701526080860151612cee90670de0b6b3a7640000615cb3565b8660600151670de0b6b3a76400008860c00151612d0b9190615d0d565b612d159190615cf9565b1115612d535760405162461bcd60e51b815260206004820152600d60248201526c4869676820736c69707061676560981b6044820152606401610a9f565b60c0860151606754612d78916101009091046001600160a01b03169033903090613ee5565b845160009080612df8575086600001516001600160a01b03166311f2d4946040518163ffffffff1660e01b815260040160206040518083038186803b158015612dc057600080fd5b505afa158015612dd4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612df89190615800565b612e03578651612e78565b86600001516001600160a01b031663d03ecc646040518163ffffffff1660e01b815260040160206040518083038186803b158015612e4057600080fd5b505afa158015612e54573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e789190615311565b865190915015612fe5578651604080890151905163140e25ad60e31b81526001600160a01b039092169163a0712d6891612eb89160040190815260200190565b600060405180830381600087803b158015612ed257600080fd5b505af1158015612ee6573d6000803e3d6000fd5b50505050612efd87600001518860400151886141a9565b607e5487516040516318dc4baf60e11b81526001600160a01b039182166004820152600092839216906331b8975e90602401604080518083038186803b158015612f4657600080fd5b505afa158015612f5a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f7e919061532d565b91509150612f958960400151838b6000015161444d565b612fa88960400151828b6000015161444d565b885160408a0151612fc3916001600160a01b038516916126e2565b885160408a0151612fde916001600160a01b038416916126e2565b50506131bb565b600087604001518410612ff9576000613009565b8388604001516130099190615d2c565b9050801561313c576085548851604051630163027360e61b81526001600160a01b03909216916358c09cc091613043918590600401615aef565b600060405180830381600087803b15801561305d57600080fd5b505af1158015613071573d6000803e3d6000fd5b5050895160405163140e25ad60e31b8152600481018590526001600160a01b03909116925063a0712d689150602401600060405180830381600087803b1580156130ba57600080fd5b505af11580156130ce573d6000803e3d6000fd5b505089516001600160a01b03166000908152606d60205260409020546130f79250839150615cb3565b88516001600160a01b039081166000908152606d60209081526040808320949094559185168152608b9091529081208054839290613136908490615cb3565b90915550505b608554885160408a01516001600160a01b039092169163828fce889190613164908590615d2c565b8b602001516040518463ffffffff1660e01b815260040161318793929190615b08565b600060405180830381600087803b1580156131a157600080fd5b505af11580156131b5573d6000803e3d6000fd5b50505050505b600080600089600001516001600160a01b031663cc2ee1966040518163ffffffff1660e01b815260040160606040518083038186803b1580156131fd57600080fd5b505afa158015613211573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613235919061581c565b919450925090506000808b60200151600281111561326357634e487b7160e01b600052602160045260246000fd5b1461329f5760018b60200151600281111561328e57634e487b7160e01b600052602160045260246000fd5b1461329957816132a1565b826132a1565b835b90506132c5338c60400151836001600160a01b03166126e29092919063ffffffff16565b89511580156132d657506000608054115b80156132f757506080548b60c001518c604001516132f49190615d2c565b10155b156133e057600061330b8c600001516139b8565b91505061271a81141561337d576081548c516040516375c1f9a560e11b81526001600160a01b03918216600482015291169063eb83f34a90602401600060405180830381600087803b15801561336057600080fd5b505af1158015613374573d6000803e3d6000fd5b505050506133de565b6081548c5160405163029a39cd60e01b81526001600160a01b03918216600482015291169063029a39cd90602401600060405180830381600087803b1580156133c557600080fd5b505af11580156133d9573d6000803e3d6000fd5b505050505b505b8951613472906133f1578b51613466565b8b600001516001600160a01b031663d03ecc646040518163ffffffff1660e01b815260040160206040518083038186803b15801561342e57600080fd5b505afa158015613442573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134669190615311565b868d60c00151336145d5565b608a546001600160a01b038681166000818152608b60205260409081902054905163ba0ed4ed60e01b81526004810191909152602481019190915291169063ba0ed4ed9060440160206040518083038186803b1580156134d157600080fd5b505afa1580156134e5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135099190615800565b6135485760405162461bcd60e51b815260206004820152601060248201526f5269736b20697320746f20686967682160801b6044820152606401610a9f565b89516135d390613559578b5161483a565b8b600001516001600160a01b031663d03ecc646040518163ffffffff1660e01b815260040160206040518083038186803b15801561359657600080fd5b505afa1580156135aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135ce9190615311565b61483a565b6071546001600160a01b03161561364d5760715460c08c01516040516302c7739b60e01b81526001600160a01b03909216916302c7739b9161361a91339190600401615aef565b600060405180830381600087803b15801561363457600080fd5b505af1158015613648573d6000803e3d6000fd5b505050505b7ff3bfbc0822d1ed667a2b298e71e0304f2c1f4685398189d7c39e412f733150f4338c600001518d602001518e604001518f60c00151606760019054906101000a90046001600160a01b0316876040516136ad9796959493929190615a28565b60405180910390a15050505050505050505050565b60008060038360028111156136e757634e487b7160e01b600052602160045260246000fd5b6136f2906001615cb3565b6136fc9190615d8a565b600281111561371b57634e487b7160e01b600052602160045260246000fd5b90506000600384600281111561374157634e487b7160e01b600052602160045260246000fd5b61374c906002615cb3565b6137569190615d8a565b600281111561377557634e487b7160e01b600052602160045260246000fd5b9050600080613785878585614b41565b915091508082116137965780613798565b815b979650505050505050565b607e546040805161010081019091526001600160a01b0387811682526000921690630381cd0990602081018860028111156137ee57634e487b7160e01b600052602160045260246000fd5b81526020810188905260408101879052606081018690526085546001600160a01b0316608082015260a0016138228a614d31565b81526020016138308a612326565b8152506040518263ffffffff1660e01b815260040161384f9190615c04565b60206040518083038186803b15801561386757600080fd5b505afa15801561387b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061389f9190615898565b90505b95945050505050565b6077546000906001600160a01b03838116911614156138c8575060015b6075546001600160a01b03838116911614156138e2575060025b6076546001600160a01b03838116911614156110ae57506003919050565b80516000901561398157600086600281111561392c57634e487b7160e01b600052602160045260246000fd5b1480156139455750600085118015613945575060735485105b1561397c57600080613964846060015185602001518660400151614b41565b915091508082116139755781613977565b805b925050505b610a43565b600061398c88612326565b905080861061399b578561399d565b805b95506139ac8888888888614d71565b98975050505050505050565b6040516308208aaf60e21b815260006004820181905290819083906001600160a01b038216906320822abc9060240160206040518083038186803b1580156139ff57600080fd5b505afa158015613a13573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a379190615898565b9250806001600160a01b03166311f2d4946040518163ffffffff1660e01b815260040160206040518083038186803b158015613a7257600080fd5b505afa158015613a86573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613aaa9190615800565b613ab5576000613b2d565b6040516308208aaf60e21b8152600160048201526001600160a01b038216906320822abc9060240160206040518083038186803b158015613af557600080fd5b505afa158015613b09573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b2d9190615898565b915050915091565b600080866002811115613b5857634e487b7160e01b600052602160045260246000fd5b1415610a4357607e5460009081906001600160a01b0316634ab96c838a613b7e81612326565b6040518363ffffffff1660e01b8152600401613b9b929190615aef565b604080518083038186803b158015613bb257600080fd5b505afa158015613bc6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613bea91906158e9565b91509150600082118015613bfe5750600081115b15613c62576000613c1e856060015186602001518a868b6000808d613c6e565b90506000613c3b866060015187604001518b868c6000808e613c6e565b9050600082118015613c4d5750600081115b15613c5f57613c5c8183615cb3565b94505b50505b50509695505050505050565b60008083613c8957613c848a8a89600080614d71565b613c8b565b845b90506000613c998b8b6136c2565b9050818911613e05576000613cb18c8c8c86866137a3565b9050670de0b6b3a7640000613cc6868e614fb3565b613cd890670de0b6b3a7640000615cb3565b613ce2908b615d0d565b613cec9190615cf9565b607e54604051632b4b76a960e21b81526004810184905260248101839052604481018b9052606481018d9052919a506000916001600160a01b039091169063ad2ddaa49060840160206040518083038186803b158015613d4b57600080fd5b505afa158015613d5f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d839190615898565b60685460405163edc892e160e01b8152600481018390529192506001600160a01b03169063edc892e19060240160206040518083038186803b158015613dc857600080fd5b505afa158015613ddc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e009190615898565b945050505b505098975050505050505050565b6000613e68826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166150829092919063ffffffff16565b8051909150156127385780806020019051810190613e869190615800565b6127385760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610a9f565b6040516001600160a01b0380851660248301528316604482015260648101829052613f1d9085906323b872dd60e01b90608401612701565b50505050565b613f2c82610f9c565b613f665760405162461bcd60e51b815260206004820152600b60248201526a4e6f742074726164696e6760a81b6044820152606401610a9f565b6000826001600160a01b0316631a1dbabb6040518163ffffffff1660e01b815260040160206040518083038186803b158015613fa157600080fd5b505afa158015613fb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613fd99190615898565b9050816002811115613ffb57634e487b7160e01b600052602160045260246000fd5b81116127385760405162461bcd60e51b815260206004820152600b60248201526a496e76616c696420706f7360a81b6044820152606401610a9f565b600081156140ce57607e546001600160a01b031663a119612d8561405a81612326565b6040518363ffffffff1660e01b8152600401614077929190615aef565b60206040518083038186803b15801561408f57600080fd5b505afa1580156140a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140c79190615898565b9050610c5f565b607e546040516350d851a160e01b81526001600160a01b03909116906350d851a1906141009087908790600401615a78565b60206040518083038186803b15801561411857600080fd5b505afa15801561412c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fe59190615898565b607a546000906001600160a01b038381169116146110ae576001600160a01b03821660009081526082602052604090205461418d576070546115d5565b506001600160a01b031660009081526082602052604090205490565b607e54606082015160855460405163c2edfc7360e01b81526001600160a01b03878116600483015260009485949082169363755cc89c939192169063c2edfc739060240160206040518083038186803b15801561420557600080fd5b505afa158015614219573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061423d9190615311565b866020015187604001516040518563ffffffff1660e01b815260040161426694939291906159f6565b604080518083038186803b15801561427d57600080fd5b505afa158015614291573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142b591906158e9565b9150915060008483106142c95760006142d3565b6142d38386615d2c565b905060008583106142e55760006142ef565b6142ef8387615d2c565b905060008183106143005782614302565b815b905080156112b8576085546060870151604051630163027360e61b81526001600160a01b03909216916358c09cc09161433f918590600401615aef565b600060405180830381600087803b15801561435957600080fd5b505af115801561436d573d6000803e3d6000fd5b505050606087015160405163140e25ad60e31b8152600481018490526001600160a01b03909116915063a0712d6890602401600060405180830381600087803b1580156143b957600080fd5b505af11580156143cd573d6000803e3d6000fd5b50505060608701516001600160a01b03166000908152606d60205260409020546143f991508290615cb3565b6060870180516001600160a01b039081166000908152606d602090815260408083209590955592519091168152608b909152908120805483929061443e908490615cb3565b90915550505050505050505050565b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a082319060240160206040518083038186803b15801561448f57600080fd5b505afa1580156144a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144c79190615898565b905080841115613f1d57608560009054906101000a90046001600160a01b03166001600160a01b03166352129e48836001600160a01b031663d03ecc646040518163ffffffff1660e01b815260040160206040518083038186803b15801561452e57600080fd5b505afa158015614542573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145669190615311565b6145708488615d2c565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015260248101919091529086166044820152606401600060405180830381600087803b1580156145c157600080fd5b505af11580156112b8573d6000803e3d6000fd5b6000806145e183614150565b90508015614646576145fb81670de0b6b3a7640000615cb3565b61460d670de0b6b3a764000086615d0d565b6146179190615cf9565b6146219085615d2c565b606e546067549193506146469161010090046001600160a01b039081169116846126e2565b6068546000906001600160a01b03166317fd849a6146648588615d2c565b6040518263ffffffff1660e01b815260040161468291815260200190565b60206040518083038186803b15801561469a57600080fd5b505afa1580156146ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146d29190615898565b6001600160a01b0388166000908152606d6020526040902054909150811015614739576001600160a01b0387166000908152606d6020526040902054614719908290615d2c565b6001600160a01b0388166000908152606d6020526040902081905561473c565b60005b6001600160a01b038089166000908152606d60209081526040808320949094559189168152608b90915220548110156147b3576001600160a01b0386166000908152608b6020526040902054614793908290615d2c565b6001600160a01b0387166000908152608b602052604090208190556147b6565b60005b6001600160a01b0387166000908152608b6020526040902055607954158015906147ea57506078546001600160a01b031615155b15611716576000607954670de0b6b3a76400006148079190615cb3565b614819670de0b6b3a764000088615d0d565b6148239190615cf9565b61482d9087615d2c565b90506112b8858288615091565b60855460405163f475f13b60e01b81526001600160a01b038381166004830152600092169063f475f13b90602401602060405180830381600087803b15801561488257600080fd5b505af1158015614896573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148ba9190615311565b6067546040516370a0823160e01b81523060048201529192506000916101009091046001600160a01b0316906370a082319060240160206040518083038186803b15801561490757600080fd5b505afa15801561491b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061493f9190615898565b11156149e2576067546040516370a0823160e01b81523060048201526149e29183916101009091046001600160a01b0316906370a082319060240160206040518083038186803b15801561499257600080fd5b505afa1580156149a6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906149ca9190615898565b60675461010090046001600160a01b031691906126e2565b6000806000846001600160a01b031663cc2ee1966040518163ffffffff1660e01b815260040160606040518083038186803b158015614a2057600080fd5b505afa158015614a34573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614a58919061581c565b607e54604051637512c94560e11b81526001600160a01b038a8116600483015230602483015294975092955090935060009283928392919091169063ea25928a9060440160606040518083038186803b158015614ab457600080fd5b505afa158015614ac8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614aec9190615937565b919450925090508215614b0d57614b0d6001600160a01b03871688856126e2565b8115614b2757614b276001600160a01b03861688846126e2565b80156112b8576112b86001600160a01b03851688836126e2565b607e5460405162f54ffd60e81b81526000918291829182916001600160a01b039091169063f54ffd0090614b7d908a908a908a90600401615ac5565b604080518083038186803b158015614b9457600080fd5b505afa158015614ba8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614bcc91906158e9565b915091506000614bdb88612326565b9050808310614bea5782614bec565b805b9250808210614bfb5781614bfd565b805b607e5460855460405163c2edfc7360e01b81526001600160a01b038c81166004830152939550600093849381169263755cc89c928e929091169063c2edfc739060240160206040518083038186803b158015614c5857600080fd5b505afa158015614c6c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614c909190615311565b8c8c6040518563ffffffff1660e01b8152600401614cb194939291906159f6565b604080518083038186803b158015614cc857600080fd5b505afa158015614cdc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614d0091906158e9565b91509150614d128a8a87856001614d71565b9650614d228a8986846001614d71565b95505050505050935093915050565b600080614d3d836139b8565b50600081815260896020526040902054909150614d5c57606b54610c5f565b60009081526089602052604090205492915050565b60008084118015614d83575060735484105b156138a257670de0b6b3a7640000606a54670de0b6b3a7640000614da79190615cb3565b614db19086615d0d565b614dbb9190615cf9565b935081614ec357607e5460855460405163c2edfc7360e01b81526001600160a01b0389811660048301529283169263e468265c928a928a929091169063c2edfc739060240160206040518083038186803b158015614e1857600080fd5b505afa158015614e2c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614e509190615311565b6040518463ffffffff1660e01b8152600401614e6e93929190615a95565b60206040518083038186803b158015614e8657600080fd5b505afa158015614e9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614ebe9190615898565b614ec5565b825b607e54608a5460405163279660a560e11b81526001600160a01b038a811660048301529396509183169263f947c6b392911690634f2cc14a9060240160206040518083038186803b158015614f1957600080fd5b505afa158015614f2d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614f519190615898565b6001600160a01b0389166000908152606d60205260409020548787614f758c614d31565b6040516001600160e01b031960e088901b1681526004810195909552602485019390935260448401919091526064830152608482015260a40161384f565b6000806000614fc1846139b8565b9150915060008082118015614fee5750600083815260866020908152604080832085845290915290205415155b61501157600083815260866020908152604080832083805290915290205461502c565b60008381526086602090815260408083208584529091529020545b905085615072573360009081526083602052604090205461505d576000811161505757606a54610a43565b80610a43565b33600090815260836020526040902054610a43565b600081116138a257606a54610a43565b6060611fe584846000856151a4565b607854604051630293b59d60e31b81526001600160a01b038581166004830152600092169063149dace89060240160206040518083038186803b1580156150d757600080fd5b505afa1580156150eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061510f9190615311565b90506001600160a01b0381161580159061512b57506000607954115b15613f1d5760675461514c9061010090046001600160a01b031682856126e2565b604080516001600160a01b03808416825286166020820152908101849052606081018390527f8fa68a6a8e2fc9ff758a6e64afba8bc2f66fb082999a2c5225c8c49633faded49060800160405180910390a150505050565b6060824710156152055760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610a9f565b843b6152535760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610a9f565b600080866001600160a01b0316858760405161526f91906159da565b60006040518083038185875af1925050503d80600081146152ac576040519150601f19603f3d011682016040523d82523d6000602084013e6152b1565b606091505b5091509150613798828286606083156152cb575081610c5f565b8251156152db5782518084602001fd5b8160405162461bcd60e51b8152600401610a9f9190615b70565b600060208284031215615306578081fd5b8135610c5f81615dca565b600060208284031215615322578081fd5b8151610c5f81615dca565b6000806040838503121561533f578081fd5b825161534a81615dca565b602084015190925061535b81615dca565b809150509250929050565b60008060008060008060c0878903121561537e578182fd5b863561538981615dca565b9550602087013561539981615dca565b945060408701356153a981615dca565b935060608701356153b981615dca565b925060808701356153c981615ddf565b8092505060a087013590509295509295509295565b600080604083850312156153f0578182fd5b82356153fb81615dca565b9150602083013561535b81615ddf565b60008060008060008060008060006101208a8c031215615429578283fd5b893561543481615dca565b985060208a013561544481615dca565b975060408a013561545481615dca565b965060608a013561546481615dca565b955060808a013561547481615dca565b945060a08a013561548481615dca565b935060c08a013561549481615dca565b925060e08a01356154a481615dca565b91506101008a01356154b581615dca565b809150509295985092959850929598565b600080600080600060a086880312156154dd578081fd5b85356154e881615dca565b945060208601356154f881615dca565b94979496505050506040830135926060810135926080909101359150565b60008060408385031215615528578182fd5b823561553381615dca565b9150602083013561535b81615ded565b600080600060608486031215615557578081fd5b833561556281615dca565b9250602084013561557281615ded565b929592945050506040919091013590565b60008060008060808587031215615598578182fd5b84356155a381615dca565b935060208501356155b381615ded565b92506040850135915060608501356155ca81615dca565b939692955090935050565b600080600080600060a086880312156155ec578283fd5b85356155f781615dca565b945060208601356154f881615ded565b60008060008060008060c0878903121561561f578384fd5b863561562a81615dca565b9550602087013561563a81615ded565b945060408701359350606087013592506080870135915060a087013561565f81615dca565b809150509295509295509295565b600080600080600080600060e0888a031215615687578081fd5b873561569281615dca565b965060208801356156a281615ded565b955060408801359450606088013593506080880135925060a08801356156c781615dca565b915060c08801356156d781615dca565b8091505092959891949750929550565b600080604083850312156156f9578182fd5b823561570481615dca565b946020939093013593505050565b600080600060608486031215615726578081fd5b833561573181615dca565b95602085013595506040909401359392505050565b60008060008060006080868803121561575d578283fd5b853567ffffffffffffffff80821115615774578485fd5b818801915088601f830112615787578485fd5b813581811115615795578586fd5b8960208260051b85010111156157a9578586fd5b602092830197509550508601356157bf81615dca565b92506040860135915060608601356157d681615ddf565b809150509295509295909350565b6000602082840312156157f5578081fd5b8135610c5f81615ddf565b600060208284031215615811578081fd5b8151610c5f81615ddf565b600080600060608486031215615830578081fd5b835161583b81615dca565b602085015190935061584c81615dca565b604085015190925061585d81615dca565b809150509250925092565b60008060006060848603121561587c578081fd5b835161588781615ded565b602085015190935061584c81615ded565b6000602082840312156158a9578081fd5b5051919050565b6000602082840312156158c1578081fd5b5035919050565b600080604083850312156158da578182fd5b50508035926020909101359150565b600080604083850312156158fb578182fd5b505080516020909101519092909150565b600080600060608486031215615920578081fd5b505081359360208301359350604090920135919050565b60008060006060848603121561594b578081fd5b8351925060208401519150604084015190509250925092565b600080600080600080600080610100898b031215615980578182fd5b505086359860208801359850604088013597606081013597506080810135965060a0810135955060c0810135945060e0013592509050565b600381106159d657634e487b7160e01b600052602160045260246000fd5b9052565b600082516159ec818460208701615d43565b9190910192915050565b6001600160a01b0385811682528416602082015260808101615a1b60408301856159b8565b6138a260608301846159b8565b6001600160a01b038881168252878116602083015260e0820190615a4f60408401896159b8565b86606084015285608084015280851660a084015280841660c08401525098975050505050505050565b6001600160a01b038316815260408101610c5f60208301846159b8565b6001600160a01b0384811682526060820190615ab460208401866159b8565b808416604084015250949350505050565b6001600160a01b038416815260608101615ae260208301856159b8565b611fe560408301846159b8565b6001600160a01b03929092168252602082015260400190565b6001600160a01b03841681526020810183905260608101611fe560408301846159b8565b6020808252825182820181905260009190848201906040850190845b81811015615b6457835183529284019291840191600101615b48565b50909695505050505050565b6020815260008251806020840152615b8f816040850160208701615d43565b601f01601f19169190910160400192915050565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b81516001600160a01b03908116825260208084015161010084019291615c2c908501826159b8565b506040840151604084015260608401516060840152608084015160808401528060a08501511660a08401525060c083015160c083015260e083015160e083015292915050565b600080821280156001600160ff1b0384900385131615615c9457615c94615d9e565b600160ff1b8390038412811615615cad57615cad615d9e565b50500190565b60008219821115615cc657615cc6615d9e565b500190565b600082615cda57615cda615db4565b600160ff1b821460001984141615615cf457615cf4615d9e565b500590565b600082615d0857615d08615db4565b500490565b6000816000190483118215151615615d2757615d27615d9e565b500290565b600082821015615d3e57615d3e615d9e565b500390565b60005b83811015615d5e578181015183820152602001615d46565b83811115613f1d5750506000910152565b6000600019821415615d8357615d83615d9e565b5060010190565b600082615d9957615d99615db4565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b6001600160a01b0381168114610bf857600080fd5b8015158114610bf857600080fd5b60038110610bf857600080fdfea2646970667358221220b81fc46b3ba61fe0eca1586212d2a5775492aa7d7d06f8583fe608241f535b0c64736f6c63430008040033
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.