Overview
ETH Balance
0 ETH
ETH Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 25 internal transactions (View All)
Advanced mode:
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
107557682 | 491 days ago | 0 ETH | ||||
107555360 | 491 days ago | 0 ETH | ||||
107555360 | 491 days ago | 0 ETH | ||||
107555360 | 491 days ago | 0 ETH | ||||
107555360 | 491 days ago | 0 ETH | ||||
107555360 | 491 days ago | 0 ETH | ||||
107555360 | 491 days ago | 0 ETH | ||||
107555185 | 491 days ago | 0 ETH | ||||
107555101 | 491 days ago | 0 ETH | ||||
107555040 | 491 days ago | 0 ETH | ||||
107555007 | 491 days ago | 0 ETH | ||||
107555004 | 491 days ago | 0 ETH | ||||
107554934 | 491 days ago | 0 ETH | ||||
107554870 | 491 days ago | 0 ETH | ||||
107554573 | 491 days ago | 0 ETH | ||||
107554573 | 491 days ago | 0 ETH | ||||
107554467 | 491 days ago | 0 ETH | ||||
107554467 | 491 days ago | 0 ETH | ||||
107554378 | 491 days ago | 0 ETH | ||||
107554169 | 491 days ago | 0 ETH | ||||
107553248 | 492 days ago | 0 ETH | ||||
107551739 | 492 days ago | 0 ETH | ||||
107551739 | 492 days ago | 0 ETH | ||||
107550760 | 492 days ago | 0 ETH | ||||
107550760 | 492 days ago | 0 ETH |
Loading...
Loading
Contract Name:
SportAMMLiquidityPoolRoundMastercopy
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; // Internal references import "./SportAMMLiquidityPoolRound.sol"; contract SportAMMLiquidityPoolRoundMastercopy is SportAMMLiquidityPoolRound { constructor() { // Freeze mastercopy on deployment so it can never be initialized with real arguments initialized = true; } }
// 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 = false; 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 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"); _; } }
// 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 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 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 "@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; } /* ========== CONSTANTS ========== */ uint private constant HUNDRED = 1e20; uint private constant ONE = 1e18; /* ========== 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; /* ========== 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; 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"); round = 1; firstRoundStartTime = block.timestamp; 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 { 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( (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); userInRound[nextRound][msg.sender] = true; 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 { require(started, "Pool has not started"); require(amountToMint > 0, "Can't commit a zero trade"); amountToMint = _transformCollateral(amountToMint); uint marketRound = getMarketRound(market); address liquidityPoolRound = _getOrCreateRoundPool(marketRound); if (marketRound == round) { sUSD.safeTransferFrom(liquidityPoolRound, address(sportsAMM), amountToMint); } 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 { 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 { 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 request withdrawal from the LP /// @param market to check /// @return roundPool the pool for the passed market function getOrCreateMarketPool(address market) external onlyAMM nonReentrant whenNotPaused returns (address roundPool) { uint marketRound = getMarketRound(market); roundPool = _getOrCreateRoundPool(marketRound); } /// @notice request withdrawal from the LP function withdrawalRequest() external nonReentrant whenNotPaused { 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"); if (!whitelistedDeposits[msg.sender]) { require( balancesPerRound[round][msg.sender] < _transformCollateral(((stakingThales.stakedBalanceOf(msg.sender) * stakedThalesMultiplier) / ONE)), "Not enough staked THALES" ); } 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 Close current round and begin next round, /// excercise options of trading markets and calculate profit and loss function closeRound() external nonReentrant whenNotPaused { 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); // calculate PnL // if no allocation for current round if (allocationPerRound[round] == 0) { profitAndLossPerRound[round] = 1; } else { profitAndLossPerRound[round] = (currentBalance * ONE) / allocationPerRound[round]; } for (uint i = 0; i < usersPerRound[round].length; i++) { address user = usersPerRound[round][i]; uint balanceAfterCurRound = (balancesPerRound[round][user] * profitAndLossPerRound[round]) / ONE; if (userInRound[round][user]) { if (!withdrawalRequested[user] && (profitAndLossPerRound[round] > 0)) { balancesPerRound[round + 1][user] = balancesPerRound[round + 1][user] + balanceAfterCurRound; userInRound[round + 1][user] = true; usersPerRound[round + 1].push(user); if (address(stakingThales) != address(0)) { stakingThales.updateVolume(user, balanceAfterCurRound); } } else { balancesPerRound[round + 1][user] = 0; sUSD.safeTransferFrom(roundPool, user, balanceAfterCurRound); withdrawalRequested[user] = false; userInRound[round + 1][user] = false; emit Claimed(user, balanceAfterCurRound); } } } //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)); 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 { SportAMMLiquidityPoolRound poolRound = SportAMMLiquidityPoolRound(roundPools[round]); ISportPositionalMarket market; for (uint i = 0; i < tradingMarketsPerRound[round].length; i++) { market = ISportPositionalMarket(tradingMarketsPerRound[round][i]); poolRound.exerciseMarketReadyToExercised(market); if (market.isDoubleChance()) { poolRound.exerciseMarketReadyToExercised(market.parentMarket()); } } } /* ========== 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]; } /// @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 = (stakedThalesForUser * stakedThalesMultiplier) / ONE; availableToDepositForUser = maxDepositForUser > (balancesPerRound[round][user] + balancesPerRound[nextRound][user]) ? (maxDepositForUser - balancesPerRound[round][user] - balancesPerRound[nextRound][user]) : 0; } /// @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 = ((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; } for (uint i = 0; i < tradingMarketsPerRound[round].length; i++) { IPositionalMarket market = IPositionalMarket(tradingMarketsPerRound[round][i]); 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++) { market = ISportPositionalMarket(tradingMarketsPerRound[round][i]); 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; } } /* ========== INTERNAL FUNCTIONS ========== */ function _transformCollateral(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), getRoundEndTime(_round + 1)); 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; } /// @notice setNeedsTransformingCollateral sets needsTransformingCollateral value /// @param _needsTransformingCollateral boolen value to be set function setNeedsTransformingCollateral(bool _needsTransformingCollateral) external onlyOwner { needsTransformingCollateral = _needsTransformingCollateral; } /// @notice Set _poolRoundMastercopy /// @param _poolRoundMastercopy to clone round pools from function setPoolRoundMastercopy(address _poolRoundMastercopy) external onlyOwner { 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 { 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 { 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 { 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 This method only serves as a failsafe to extract tokens from a pool round contract /// @param tokens to iterate and transfer /// @param account Address where to send the tokens /// @param amount Amount of tokens to be sent /// @param pool where to transfer from /// @param all ignore amount and send whole balance function transferTokensFromLiquidityPool( address[] calldata tokens, address payable account, uint amount, bool all, address pool ) external onlyOwner { require(tokens.length > 0, "tokens array cant be empty"); for (uint256 index = 0; index < tokens.length; index++) { if (all) { IERC20Upgradeable(tokens[index]).safeTransferFrom( pool, account, IERC20Upgradeable(tokens[index]).balanceOf(pool) ); } else { IERC20Upgradeable(tokens[index]).safeTransferFrom(pool, account, amount); } } } /// @notice This method only serves as a failsafe to extract tokens from this contract /// @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, "Whitelisted addresses cannot 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); } } } /// @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); } } } /* ========== MODIFIERS ========== */ modifier canDeposit(uint amount) { require(!withdrawalRequested[msg.sender], "Withdrawal is requested, cannot deposit"); require(amount >= minDepositAmount, "Amount less than minDepositAmount"); require(totalDeposited + amount <= maxAllowedDeposit, "Deposit amount exceeds AMM LP cap"); _; } modifier onlyAMM() { require(msg.sender == address(sportsAMM), "only the AMM may perform these methods"); _; } /* ========== 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); }
// 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 (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 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; 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 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 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 (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 // 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; 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 getMarketDefaultOdds(address _market, bool isSell) external view returns (uint[] memory); function isMarketInAMMTrading(address _market) 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 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); }
// 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 // 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; }
{ "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
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"contract ISportPositionalMarket","name":"market","type":"address"}],"name":"exerciseMarketReadyToExercised","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_liquidityPool","type":"address"},{"internalType":"contract IERC20Upgradeable","name":"_sUSD","type":"address"},{"internalType":"uint256","name":"_round","type":"uint256"},{"internalType":"uint256","name":"_roundStartTime","type":"uint256"},{"internalType":"uint256","name":"_roundEndTime","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liquidityPool","outputs":[{"internalType":"contract SportAMMLiquidityPool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20Upgradeable","name":"option","type":"address"},{"internalType":"uint256","name":"optionsAmount","type":"uint256"},{"internalType":"address","name":"destination","type":"address"}],"name":"moveOptions","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"round","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"roundEndTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"roundStartTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sUSD","outputs":[{"internalType":"contract IERC20Upgradeable","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
60806040526005805460ff1916905534801561001a57600080fd5b506005805460ff19166001179055610900806100376000396000f3fe608060405234801561001057600080fd5b50600436106100935760003560e01c8063bb580fbb11610066578063bb580fbb1461010f578063d13f90b414610124578063dd4f8f7414610137578063e40205d614610140578063f3d5fdd41461014957600080fd5b8063146ca53114610098578063158ef93e146100b4578063665a11ca146100d15780639324cac7146100fc575b600080fd5b6100a160025481565b6040519081526020015b60405180910390f35b6005546100c19060ff1681565b60405190151581526020016100ab565b6000546100e4906001600160a01b031681565b6040516001600160a01b0390911681526020016100ab565b6001546100e4906001600160a01b031681565b61012261011d3660046107a2565b61015c565b005b6101226101323660046106f1565b610303565b6100a160035481565b6100a160045481565b610122610157366004610761565b610427565b6000546001600160a01b0316331461018f5760405162461bcd60e51b81526004016101869061083a565b60405180910390fd5b806001600160a01b0316633f6fa6556040518163ffffffff1660e01b815260040160206040518083038186803b1580156101c857600080fd5b505afa1580156101dc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102009190610741565b1561030057604051636392a51f60e01b8152306004820152600090819081906001600160a01b03851690636392a51f9060240160606040518083038186803b15801561024b57600080fd5b505afa15801561025f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061028391906107be565b92509250925060008311806102985750600082115b806102a35750600081115b156102fc57836001600160a01b031663851492586040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156102e357600080fd5b505af11580156102f7573d6000803e3d6000fd5b505050505b5050505b50565b60055460ff161561034c5760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b6044820152606401610186565b6005805460ff19166001908117909155600080546001600160a01b038089166001600160a01b03199283161790925582549187169116811790915560028490556003839055600482815560405163095ea7b360e01b815263095ea7b3916103cd91899160001991016001600160a01b03929092168252602082015260400190565b602060405180830381600087803b1580156103e757600080fd5b505af11580156103fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061041f9190610741565b505050505050565b6000546001600160a01b031633146104515760405162461bcd60e51b81526004016101869061083a565b6104656001600160a01b038416828461046a565b505050565b604080516001600160a01b03848116602483015260448083018590528351808403909101815260649092018352602080830180516001600160e01b031663a9059cbb60e01b17905283518085019094528084527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656490840152610465928692916000916104fa918516908490610577565b80519091501561046557808060200190518101906105189190610741565b6104655760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610186565b60606105868484600085610590565b90505b9392505050565b6060824710156105f15760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610186565b843b61063f5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610186565b600080866001600160a01b0316858760405161065b91906107eb565b60006040518083038185875af1925050503d8060008114610698576040519150601f19603f3d011682016040523d82523d6000602084013e61069d565b606091505b50915091506106ad8282866106b8565b979650505050505050565b606083156106c7575081610589565b8251156106d75782518084602001fd5b8160405162461bcd60e51b81526004016101869190610807565b600080600080600060a08688031215610708578081fd5b8535610713816108b5565b94506020860135610723816108b5565b94979496505050506040830135926060810135926080909101359150565b600060208284031215610752578081fd5b81518015158114610589578182fd5b600080600060608486031215610775578283fd5b8335610780816108b5565b9250602084013591506040840135610797816108b5565b809150509250925092565b6000602082840312156107b3578081fd5b8135610589816108b5565b6000806000606084860312156107d2578283fd5b8351925060208401519150604084015190509250925092565b600082516107fd818460208701610889565b9190910192915050565b6020815260008251806020840152610826816040850160208701610889565b601f01601f19169190910160400192915050565b6020808252602f908201527f6f6e6c792074686520506f6f6c206d616e61676572206d617920706572666f7260408201526e6d207468657365206d6574686f647360881b606082015260800190565b60005b838110156108a457818101518382015260200161088c565b838111156102fc5750506000910152565b6001600160a01b038116811461030057600080fdfea2646970667358221220be797735c46190cfb07e8f42eb8c35c69427688624130434169e83eab3bd995864736f6c63430008040033
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100935760003560e01c8063bb580fbb11610066578063bb580fbb1461010f578063d13f90b414610124578063dd4f8f7414610137578063e40205d614610140578063f3d5fdd41461014957600080fd5b8063146ca53114610098578063158ef93e146100b4578063665a11ca146100d15780639324cac7146100fc575b600080fd5b6100a160025481565b6040519081526020015b60405180910390f35b6005546100c19060ff1681565b60405190151581526020016100ab565b6000546100e4906001600160a01b031681565b6040516001600160a01b0390911681526020016100ab565b6001546100e4906001600160a01b031681565b61012261011d3660046107a2565b61015c565b005b6101226101323660046106f1565b610303565b6100a160035481565b6100a160045481565b610122610157366004610761565b610427565b6000546001600160a01b0316331461018f5760405162461bcd60e51b81526004016101869061083a565b60405180910390fd5b806001600160a01b0316633f6fa6556040518163ffffffff1660e01b815260040160206040518083038186803b1580156101c857600080fd5b505afa1580156101dc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102009190610741565b1561030057604051636392a51f60e01b8152306004820152600090819081906001600160a01b03851690636392a51f9060240160606040518083038186803b15801561024b57600080fd5b505afa15801561025f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061028391906107be565b92509250925060008311806102985750600082115b806102a35750600081115b156102fc57836001600160a01b031663851492586040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156102e357600080fd5b505af11580156102f7573d6000803e3d6000fd5b505050505b5050505b50565b60055460ff161561034c5760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b6044820152606401610186565b6005805460ff19166001908117909155600080546001600160a01b038089166001600160a01b03199283161790925582549187169116811790915560028490556003839055600482815560405163095ea7b360e01b815263095ea7b3916103cd91899160001991016001600160a01b03929092168252602082015260400190565b602060405180830381600087803b1580156103e757600080fd5b505af11580156103fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061041f9190610741565b505050505050565b6000546001600160a01b031633146104515760405162461bcd60e51b81526004016101869061083a565b6104656001600160a01b038416828461046a565b505050565b604080516001600160a01b03848116602483015260448083018590528351808403909101815260649092018352602080830180516001600160e01b031663a9059cbb60e01b17905283518085019094528084527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656490840152610465928692916000916104fa918516908490610577565b80519091501561046557808060200190518101906105189190610741565b6104655760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610186565b60606105868484600085610590565b90505b9392505050565b6060824710156105f15760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610186565b843b61063f5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610186565b600080866001600160a01b0316858760405161065b91906107eb565b60006040518083038185875af1925050503d8060008114610698576040519150601f19603f3d011682016040523d82523d6000602084013e61069d565b606091505b50915091506106ad8282866106b8565b979650505050505050565b606083156106c7575081610589565b8251156106d75782518084602001fd5b8160405162461bcd60e51b81526004016101869190610807565b600080600080600060a08688031215610708578081fd5b8535610713816108b5565b94506020860135610723816108b5565b94979496505050506040830135926060810135926080909101359150565b600060208284031215610752578081fd5b81518015158114610589578182fd5b600080600060608486031215610775578283fd5b8335610780816108b5565b9250602084013591506040840135610797816108b5565b809150509250925092565b6000602082840312156107b3578081fd5b8135610589816108b5565b6000806000606084860312156107d2578283fd5b8351925060208401519150604084015190509250925092565b600082516107fd818460208701610889565b9190910192915050565b6020815260008251806020840152610826816040850160208701610889565b601f01601f19169190910160400192915050565b6020808252602f908201527f6f6e6c792074686520506f6f6c206d616e61676572206d617920706572666f7260408201526e6d207468657365206d6574686f647360881b606082015260800190565b60005b838110156108a457818101518382015260200161088c565b838111156102fc5750506000910152565b6001600160a01b038116811461030057600080fdfea2646970667358221220be797735c46190cfb07e8f42eb8c35c69427688624130434169e83eab3bd995864736f6c63430008040033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 29 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.