Source Code
Overview
ETH Balance
0 ETH
More Info
ContractCreator
Multichain Info
N/A
Loading...
Loading
Contract Name:
SpeedMarketsAMMCreator
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; // external import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@pythnetwork/pyth-sdk-solidity/IPyth.sol"; import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol"; // internal import "../utils/proxy/solidity-0.8.0/ProxyReentrancyGuard.sol"; import "../utils/proxy/solidity-0.8.0/ProxyOwned.sol"; import "../utils/proxy/solidity-0.8.0/ProxyPausable.sol"; import "../interfaces/IAddressManager.sol"; import "../interfaces/ISpeedMarketsAMM.sol"; import "../interfaces/IChainedSpeedMarketsAMM.sol"; import "./SpeedMarket.sol"; import "./SpeedMarketsAMM.sol"; import "./ChainedSpeedMarketsAMM.sol"; /// @title speed/chained markets prepared for creation with latest Pyth price contract SpeedMarketsAMMCreator is Initializable, ProxyOwned, ProxyPausable, ProxyReentrancyGuard { uint private constant ONE = 1e18; struct SpeedMarketParams { bytes32 asset; uint64 strikeTime; uint64 delta; uint strikePrice; uint strikePriceSlippage; SpeedMarket.Direction direction; address collateral; uint buyinAmount; address referrer; uint skewImpact; } struct PendingSpeedMarket { address user; bytes32 asset; uint64 strikeTime; uint64 delta; uint strikePrice; uint strikePriceSlippage; SpeedMarket.Direction direction; address collateral; uint buyinAmount; address referrer; uint skewImpact; uint256 createdAt; } struct ChainedSpeedMarketParams { bytes32 asset; uint64 timeFrame; uint strikePrice; uint strikePriceSlippage; SpeedMarket.Direction[] directions; address collateral; uint buyinAmount; address referrer; } struct PendingChainedSpeedMarket { address user; bytes32 asset; uint64 timeFrame; uint strikePrice; uint strikePriceSlippage; SpeedMarket.Direction[] directions; address collateral; uint buyinAmount; address referrer; uint256 createdAt; } uint64 public maxCreationDelay; PendingSpeedMarket[] public pendingSpeedMarkets; PendingChainedSpeedMarket[] public pendingChainedSpeedMarkets; IAddressManager public addressManager; function initialize(address _owner, address _addressManager) external initializer { setOwner(_owner); addressManager = IAddressManager(_addressManager); } /// @notice add new speed market to pending - waiting for creation /// @param _params parameters for adding pending speed market function addPendingSpeedMarket(SpeedMarketParams calldata _params) external nonReentrant notPaused { PendingSpeedMarket memory pendingSpeedMarket = PendingSpeedMarket( msg.sender, _params.asset, _params.strikeTime, _params.delta, _params.strikePrice, _params.strikePriceSlippage, _params.direction, _params.collateral, _params.buyinAmount, _params.referrer, _params.skewImpact, block.timestamp ); pendingSpeedMarkets.push(pendingSpeedMarket); emit AddSpeedMarket(pendingSpeedMarket); } /// @notice create all speed markets from pending using latest price feeds from param /// @param _priceUpdateData pyth priceUpdateData for all supported assets function createFromPendingSpeedMarkets(bytes[] calldata _priceUpdateData) external payable nonReentrant notPaused { require(pendingSpeedMarkets.length > 0, "No pending markets"); require(_priceUpdateData.length > 0, "Empty price update data"); IAddressManager.Addresses memory contractsAddresses = addressManager.getAddresses(); _updatePythPrice(contractsAddresses.pyth, _priceUpdateData); ISpeedMarketsAMM iSpeedMarketsAMM = ISpeedMarketsAMM(contractsAddresses.speedMarketsAMM); uint64 maximumPriceDelay = iSpeedMarketsAMM.maximumPriceDelay(); uint8 createdSize; // process all pending speed markets for (uint8 i = 0; i < pendingSpeedMarkets.length; i++) { PendingSpeedMarket memory pendingSpeedMarket = pendingSpeedMarkets[i]; if ((pendingSpeedMarket.createdAt + maxCreationDelay) <= block.timestamp) { // too late for processing continue; } PythStructs.Price memory pythPrice = _getPythPrice( contractsAddresses, pendingSpeedMarket.asset, maximumPriceDelay, pendingSpeedMarket.strikePrice, pendingSpeedMarket.strikePriceSlippage ); try iSpeedMarketsAMM.createNewMarket( SpeedMarketsAMM.CreateMarketParams( pendingSpeedMarket.user, pendingSpeedMarket.asset, pendingSpeedMarket.strikeTime, pendingSpeedMarket.delta, pythPrice, pendingSpeedMarket.direction, pendingSpeedMarket.collateral, pendingSpeedMarket.buyinAmount, pendingSpeedMarket.referrer, pendingSpeedMarket.skewImpact ) ) { createdSize++; } catch Error(string memory reason) { emit LogError(reason, pendingSpeedMarket); } catch (bytes memory data) { emit LogErrorData(data, pendingSpeedMarket); } } uint pendingSize = pendingSpeedMarkets.length; delete pendingSpeedMarkets; emit CreateSpeedMarkets(pendingSize, createdSize); } /// @notice create speed market /// @param _speedMarketParams parameters for creating speed market /// @param _priceUpdateData pyth priceUpdateData for all supported assets function createSpeedMarket(SpeedMarketParams calldata _speedMarketParams, bytes[] calldata _priceUpdateData) external payable nonReentrant notPaused { require(_priceUpdateData.length > 0, "Empty price update data"); IAddressManager.Addresses memory contractsAddresses = addressManager.getAddresses(); _updatePythPrice(contractsAddresses.pyth, _priceUpdateData); ISpeedMarketsAMM iSpeedMarketsAMM = ISpeedMarketsAMM(contractsAddresses.speedMarketsAMM); PythStructs.Price memory pythPrice = _getPythPrice( contractsAddresses, _speedMarketParams.asset, iSpeedMarketsAMM.maximumPriceDelay(), _speedMarketParams.strikePrice, _speedMarketParams.strikePriceSlippage ); iSpeedMarketsAMM.createNewMarket( SpeedMarketsAMM.CreateMarketParams( msg.sender, _speedMarketParams.asset, _speedMarketParams.strikeTime, _speedMarketParams.delta, pythPrice, _speedMarketParams.direction, _speedMarketParams.collateral, _speedMarketParams.buyinAmount, _speedMarketParams.referrer, _speedMarketParams.skewImpact ) ); } //////////////////chained///////////////// /// @notice add new chained speed market to pending - waiting for creation /// @param _params parameters for adding pending chained speed market function addPendingChainedSpeedMarket(ChainedSpeedMarketParams calldata _params) external nonReentrant notPaused { PendingChainedSpeedMarket memory pendingChainedSpeedMarket = PendingChainedSpeedMarket( msg.sender, _params.asset, _params.timeFrame, _params.strikePrice, _params.strikePriceSlippage, _params.directions, _params.collateral, _params.buyinAmount, _params.referrer, block.timestamp ); pendingChainedSpeedMarkets.push(pendingChainedSpeedMarket); emit AddChainedSpeedMarket(pendingChainedSpeedMarket); } /// @notice create all chained speed markets from pending using latest price feeds from param /// @param _priceUpdateData pyth priceUpdateData for all supported assets function createFromPendingChainedSpeedMarkets(bytes[] calldata _priceUpdateData) external payable nonReentrant notPaused { require(pendingChainedSpeedMarkets.length > 0, "No pending markets"); require(_priceUpdateData.length > 0, "Empty price update data"); IAddressManager.Addresses memory contractsAddresses = addressManager.getAddresses(); _updatePythPrice(contractsAddresses.pyth, _priceUpdateData); ISpeedMarketsAMM iSpeedMarketsAMM = ISpeedMarketsAMM(contractsAddresses.speedMarketsAMM); uint64 maximumPriceDelay = iSpeedMarketsAMM.maximumPriceDelay(); uint8 createdSize; // process all pending chained speed markets for (uint8 i = 0; i < pendingChainedSpeedMarkets.length; i++) { PendingChainedSpeedMarket memory pendingChainedSpeedMarket = pendingChainedSpeedMarkets[i]; if ((pendingChainedSpeedMarket.createdAt + maxCreationDelay) <= block.timestamp) { // too late for processing continue; } PythStructs.Price memory pythPrice = _getPythPrice( contractsAddresses, pendingChainedSpeedMarket.asset, maximumPriceDelay, pendingChainedSpeedMarket.strikePrice, pendingChainedSpeedMarket.strikePriceSlippage ); try IChainedSpeedMarketsAMM(addressManager.getAddress("ChainedSpeedMarketsAMM")).createNewMarket( ChainedSpeedMarketsAMM.CreateMarketParams( pendingChainedSpeedMarket.user, pendingChainedSpeedMarket.asset, pendingChainedSpeedMarket.timeFrame, pythPrice, pendingChainedSpeedMarket.directions, pendingChainedSpeedMarket.collateral, pendingChainedSpeedMarket.buyinAmount, pendingChainedSpeedMarket.referrer ) ) { createdSize++; } catch Error(string memory reason) { emit LogChainedError(reason, pendingChainedSpeedMarket); } catch (bytes memory data) { emit LogChainedErrorData(data, pendingChainedSpeedMarket); } } uint pendingSize = pendingChainedSpeedMarkets.length; delete pendingChainedSpeedMarkets; emit CreateSpeedMarkets(pendingSize, createdSize); } /// @notice create chained speed market /// @param _chainedMarketParams parameters for creating chained speed market /// @param _priceUpdateData pyth priceUpdateData for all supported assets function createChainedSpeedMarket( ChainedSpeedMarketParams calldata _chainedMarketParams, bytes[] calldata _priceUpdateData ) external payable nonReentrant notPaused { require(_priceUpdateData.length > 0, "Empty price update data"); IAddressManager.Addresses memory contractsAddresses = addressManager.getAddresses(); _updatePythPrice(contractsAddresses.pyth, _priceUpdateData); ISpeedMarketsAMM iSpeedMarketsAMM = ISpeedMarketsAMM(contractsAddresses.speedMarketsAMM); PythStructs.Price memory pythPrice = _getPythPrice( contractsAddresses, _chainedMarketParams.asset, iSpeedMarketsAMM.maximumPriceDelay(), _chainedMarketParams.strikePrice, _chainedMarketParams.strikePriceSlippage ); IChainedSpeedMarketsAMM(addressManager.getAddress("ChainedSpeedMarketsAMM")).createNewMarket( ChainedSpeedMarketsAMM.CreateMarketParams( msg.sender, _chainedMarketParams.asset, _chainedMarketParams.timeFrame, pythPrice, _chainedMarketParams.directions, _chainedMarketParams.collateral, _chainedMarketParams.buyinAmount, _chainedMarketParams.referrer ) ); } function _updatePythPrice(address _pyth, bytes[] calldata _priceUpdateData) internal { IPyth iPyth = IPyth(_pyth); iPyth.updatePriceFeeds{value: iPyth.getUpdateFee(_priceUpdateData)}(_priceUpdateData); } function _getPythPrice( IAddressManager.Addresses memory _contractsAddresses, bytes32 _asset, uint64 _maximumPriceDelay, uint _strikePrice, uint _strikePriceSlippage ) internal view returns (PythStructs.Price memory pythPrice) { ISpeedMarketsAMM iSpeedMarketsAMM = ISpeedMarketsAMM(_contractsAddresses.speedMarketsAMM); IPyth iPyth = IPyth(_contractsAddresses.pyth); pythPrice = iPyth.getPriceUnsafe(iSpeedMarketsAMM.assetToPythId(_asset)); require((pythPrice.publishTime + _maximumPriceDelay) > block.timestamp && pythPrice.price > 0, "Stale price"); int64 maxPrice = int64(uint64((_strikePrice * (ONE + _strikePriceSlippage)) / ONE)); int64 minPrice = int64(uint64((_strikePrice * (ONE - _strikePriceSlippage)) / ONE)); require(pythPrice.price <= maxPrice && pythPrice.price >= minPrice, "Pyth price exceeds slippage"); } //////////////////getters///////////////// /// @notice get length of pending speed markets function getPendingSpeedMarketsSize() external view returns (uint) { return pendingSpeedMarkets.length; } /// @notice get length of pending chained speed markets function getPendingChainedSpeedMarketsSize() external view returns (uint) { return pendingChainedSpeedMarkets.length; } //////////////////setters///////////////// /// @notice Set address of address manager /// @param _addressManager to use address for fetching other contract addresses function setAddressManager(address _addressManager) external onlyOwner { addressManager = IAddressManager(_addressManager); emit SetAddressManager(_addressManager); } /// @notice Set max creation delay function setMaxCreationDelay(uint64 _maxCreationDelay) external onlyOwner { maxCreationDelay = _maxCreationDelay; emit SetMaxCreationDelay(_maxCreationDelay); } //////////////////events///////////////// event AddSpeedMarket(PendingSpeedMarket _pendingSpeedMarket); event AddChainedSpeedMarket(PendingChainedSpeedMarket _pendingChainedSpeedMarket); event CreateSpeedMarkets(uint _pendingSize, uint8 _createdSize); event SetAddressManager(address _addressManager); event SetMaxCreationDelay(uint64 _maxCreationDelay); event LogError(string _errorMessage, PendingSpeedMarket _pendingSpeedMarket); event LogErrorData(bytes _data, PendingSpeedMarket _pendingSpeedMarket); event LogChainedError(string _errorMessage, PendingChainedSpeedMarket _pendingChainedSpeedMarket); event LogChainedErrorData(bytes _data, PendingChainedSpeedMarket _pendingChainedSpeedMarket); }
// 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: Apache-2.0 pragma solidity ^0.8.0; import "./PythStructs.sol"; import "./IPythEvents.sol"; /// @title Consume prices from the Pyth Network (https://pyth.network/). /// @dev Please refer to the guidance at https://docs.pyth.network/consumers/best-practices for how to consume prices safely. /// @author Pyth Data Association interface IPyth is IPythEvents { /// @notice Returns the period (in seconds) that a price feed is considered valid since its publish time function getValidTimePeriod() external view returns (uint validTimePeriod); /// @notice Returns the price and confidence interval. /// @dev Reverts if the price has not been updated within the last `getValidTimePeriod()` seconds. /// @param id The Pyth Price Feed ID of which to fetch the price and confidence interval. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getPrice( bytes32 id ) external view returns (PythStructs.Price memory price); /// @notice Returns the exponentially-weighted moving average price and confidence interval. /// @dev Reverts if the EMA price is not available. /// @param id The Pyth Price Feed ID of which to fetch the EMA price and confidence interval. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getEmaPrice( bytes32 id ) external view returns (PythStructs.Price memory price); /// @notice Returns the price of a price feed without any sanity checks. /// @dev This function returns the most recent price update in this contract without any recency checks. /// This function is unsafe as the returned price update may be arbitrarily far in the past. /// /// Users of this function should check the `publishTime` in the price to ensure that the returned price is /// sufficiently recent for their application. If you are considering using this function, it may be /// safer / easier to use either `getPrice` or `getPriceNoOlderThan`. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getPriceUnsafe( bytes32 id ) external view returns (PythStructs.Price memory price); /// @notice Returns the price that is no older than `age` seconds of the current time. /// @dev This function is a sanity-checked version of `getPriceUnsafe` which is useful in /// applications that require a sufficiently-recent price. Reverts if the price wasn't updated sufficiently /// recently. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getPriceNoOlderThan( bytes32 id, uint age ) external view returns (PythStructs.Price memory price); /// @notice Returns the exponentially-weighted moving average price of a price feed without any sanity checks. /// @dev This function returns the same price as `getEmaPrice` in the case where the price is available. /// However, if the price is not recent this function returns the latest available price. /// /// The returned price can be from arbitrarily far in the past; this function makes no guarantees that /// the returned price is recent or useful for any particular application. /// /// Users of this function should check the `publishTime` in the price to ensure that the returned price is /// sufficiently recent for their application. If you are considering using this function, it may be /// safer / easier to use either `getEmaPrice` or `getEmaPriceNoOlderThan`. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getEmaPriceUnsafe( bytes32 id ) external view returns (PythStructs.Price memory price); /// @notice Returns the exponentially-weighted moving average price that is no older than `age` seconds /// of the current time. /// @dev This function is a sanity-checked version of `getEmaPriceUnsafe` which is useful in /// applications that require a sufficiently-recent price. Reverts if the price wasn't updated sufficiently /// recently. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getEmaPriceNoOlderThan( bytes32 id, uint age ) external view returns (PythStructs.Price memory price); /// @notice Update price feeds with given update messages. /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling /// `getUpdateFee` with the length of the `updateData` array. /// Prices will be updated if they are more recent than the current stored prices. /// The call will succeed even if the update is not the most recent. /// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid. /// @param updateData Array of price update data. function updatePriceFeeds(bytes[] calldata updateData) external payable; /// @notice Wrapper around updatePriceFeeds that rejects fast if a price update is not necessary. A price update is /// necessary if the current on-chain publishTime is older than the given publishTime. It relies solely on the /// given `publishTimes` for the price feeds and does not read the actual price update publish time within `updateData`. /// /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling /// `getUpdateFee` with the length of the `updateData` array. /// /// `priceIds` and `publishTimes` are two arrays with the same size that correspond to senders known publishTime /// of each priceId when calling this method. If all of price feeds within `priceIds` have updated and have /// a newer or equal publish time than the given publish time, it will reject the transaction to save gas. /// Otherwise, it calls updatePriceFeeds method to update the prices. /// /// @dev Reverts if update is not needed or the transferred fee is not sufficient or the updateData is invalid. /// @param updateData Array of price update data. /// @param priceIds Array of price ids. /// @param publishTimes Array of publishTimes. `publishTimes[i]` corresponds to known `publishTime` of `priceIds[i]` function updatePriceFeedsIfNecessary( bytes[] calldata updateData, bytes32[] calldata priceIds, uint64[] calldata publishTimes ) external payable; /// @notice Returns the required fee to update an array of price updates. /// @param updateData Array of price update data. /// @return feeAmount The required fee in Wei. function getUpdateFee( bytes[] calldata updateData ) external view returns (uint feeAmount); /// @notice Parse `updateData` and return price feeds of the given `priceIds` if they are all published /// within `minPublishTime` and `maxPublishTime`. /// /// You can use this method if you want to use a Pyth price at a fixed time and not the most recent price; /// otherwise, please consider using `updatePriceFeeds`. This method does not store the price updates on-chain. /// /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling /// `getUpdateFee` with the length of the `updateData` array. /// /// /// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid or there is /// no update for any of the given `priceIds` within the given time range. /// @param updateData Array of price update data. /// @param priceIds Array of price ids. /// @param minPublishTime minimum acceptable publishTime for the given `priceIds`. /// @param maxPublishTime maximum acceptable publishTime for the given `priceIds`. /// @return priceFeeds Array of the price feeds corresponding to the given `priceIds` (with the same order). function parsePriceFeedUpdates( bytes[] calldata updateData, bytes32[] calldata priceIds, uint64 minPublishTime, uint64 maxPublishTime ) external payable returns (PythStructs.PriceFeed[] memory priceFeeds); }
// SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.0; contract PythStructs { // A price with a degree of uncertainty, represented as a price +- a confidence interval. // // The confidence interval roughly corresponds to the standard error of a normal distribution. // Both the price and confidence are stored in a fixed-point numeric representation, // `x * (10^expo)`, where `expo` is the exponent. // // Please refer to the documentation at https://docs.pyth.network/consumers/best-practices for how // to how this price safely. struct Price { // Price int64 price; // Confidence interval around the price uint64 conf; // Price exponent int32 expo; // Unix timestamp describing when the price was published uint publishTime; } // PriceFeed represents a current aggregate price from pyth publisher feeds. struct PriceFeed { // The price ID. bytes32 id; // Latest available price Price price; // Latest available exponentially-weighted moving average price Price emaPrice; } }
// 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.8.0; // Inheritance import "./ProxyOwned.sol"; // Clone of syntetix contract without constructor contract ProxyPausable is ProxyOwned { uint public lastPauseTime; bool public paused; /** * @notice Change the paused state of the contract * @dev Only the contract owner may call this. */ function setPaused(bool _paused) external onlyOwner { // Ensure we're actually changing the state before we do anything if (_paused == paused) { return; } // Set our paused state. paused = _paused; // If applicable, set the last pause time. if (paused) { lastPauseTime = block.timestamp; } // Let everyone know that our pause state has changed. emit PauseChanged(paused); } event PauseChanged(bool isPaused); modifier notPaused { require(!paused, "This action cannot be performed while the contract is paused"); _; } }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; interface IAddressManager { struct Addresses { address safeBox; address referrals; address stakingThales; address multiCollateralOnOffRamp; address pyth; address speedMarketsAMM; } function safeBox() external view returns (address); function referrals() external view returns (address); function stakingThales() external view returns (address); function multiCollateralOnOffRamp() external view returns (address); function pyth() external view returns (address); function speedMarketsAMM() external view returns (address); function getAddresses() external view returns (Addresses memory); function getAddresses(string[] calldata _contractNames) external view returns (address[] memory contracts); function getAddress(string memory _contractName) external view returns (address contract_); function checkIfContractExists(string memory _contractName) external view returns (bool contractExists); }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol"; import "../SpeedMarkets/SpeedMarket.sol"; import "../SpeedMarkets/SpeedMarketsAMM.sol"; interface ISpeedMarketsAMM { struct Params { bool supportedAsset; uint safeBoxImpact; uint64 maximumPriceDelay; } function sUSD() external view returns (IERC20Upgradeable); function createNewMarket(SpeedMarketsAMM.CreateMarketParams calldata _params) external; function supportedAsset(bytes32 _asset) external view returns (bool); function assetToPythId(bytes32 _asset) external view returns (bytes32); function minBuyinAmount() external view returns (uint); function maxBuyinAmount() external view returns (uint); function minimalTimeToMaturity() external view returns (uint); function maximalTimeToMaturity() external view returns (uint); function maximumPriceDelay() external view returns (uint64); function maximumPriceDelayForResolving() external view returns (uint64); function timeThresholdsForFees(uint _index) external view returns (uint); function lpFees(uint _index) external view returns (uint); function lpFee() external view returns (uint); function maxSkewImpact() external view returns (uint); function safeBoxImpact() external view returns (uint); function marketHasCreatedAtAttribute(address _market) external view returns (bool); function marketHasFeeAttribute(address _market) external view returns (bool); function maxRiskPerAsset(bytes32 _asset) external view returns (uint); function currentRiskPerAsset(bytes32 _asset) external view returns (uint); function maxRiskPerAssetAndDirection(bytes32 _asset, SpeedMarket.Direction _direction) external view returns (uint); function currentRiskPerAssetAndDirection(bytes32 _asset, SpeedMarket.Direction _direction) external view returns (uint); function whitelistedAddresses(address _wallet) external view returns (bool); function getLengths(address _user) external view returns (uint[5] memory); function getParams(bytes32 _asset) external view returns (Params memory); }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol"; import "../SpeedMarkets/SpeedMarket.sol"; import "../SpeedMarkets/ChainedSpeedMarketsAMM.sol"; interface IChainedSpeedMarketsAMM { function sUSD() external view returns (IERC20Upgradeable); function createNewMarket(ChainedSpeedMarketsAMM.CreateMarketParams calldata _params) external; function minChainedMarkets() external view returns (uint); function maxChainedMarkets() external view returns (uint); function minTimeFrame() external view returns (uint64); function maxTimeFrame() external view returns (uint64); function minBuyinAmount() external view returns (uint); function maxBuyinAmount() external view returns (uint); function maxProfitPerIndividualMarket() external view returns (uint); function payoutMultipliers(uint _index) external view returns (uint); function maxRisk() external view returns (uint); function currentRisk() external view returns (uint); function getLengths(address _user) external view returns (uint[4] memory); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import "../interfaces/ISpeedMarketsAMM.sol"; contract SpeedMarket { using SafeERC20Upgradeable for IERC20Upgradeable; struct InitParams { address _speedMarketsAMM; address _user; bytes32 _asset; uint64 _strikeTime; int64 _strikePrice; uint64 _strikePricePublishTime; Direction _direction; uint _buyinAmount; uint _safeBoxImpact; uint _lpFee; } enum Direction { Up, Down } address public user; bytes32 public asset; uint64 public strikeTime; int64 public strikePrice; uint64 public strikePricePublishTime; Direction public direction; uint public buyinAmount; bool public resolved; int64 public finalPrice; Direction public result; ISpeedMarketsAMM public speedMarketsAMM; uint public safeBoxImpact; uint public lpFee; uint256 public createdAt; /* ========== CONSTRUCTOR ========== */ bool public initialized = false; function initialize(InitParams calldata params) external { require(!initialized, "Speed market already initialized"); initialized = true; speedMarketsAMM = ISpeedMarketsAMM(params._speedMarketsAMM); user = params._user; asset = params._asset; strikeTime = params._strikeTime; strikePrice = params._strikePrice; strikePricePublishTime = params._strikePricePublishTime; direction = params._direction; buyinAmount = params._buyinAmount; safeBoxImpact = params._safeBoxImpact; lpFee = params._lpFee; speedMarketsAMM.sUSD().approve(params._speedMarketsAMM, type(uint256).max); createdAt = block.timestamp; } function resolve(int64 _finalPrice) external onlyAMM { require(!resolved, "already resolved"); require(block.timestamp > strikeTime, "not ready to be resolved"); resolved = true; finalPrice = _finalPrice; if (finalPrice < strikePrice) { result = Direction.Down; } else if (finalPrice > strikePrice) { result = Direction.Up; } else { result = direction == Direction.Up ? Direction.Down : Direction.Up; } if (direction == result) { speedMarketsAMM.sUSD().safeTransfer(user, speedMarketsAMM.sUSD().balanceOf(address(this))); } else { speedMarketsAMM.sUSD().safeTransfer(address(speedMarketsAMM), speedMarketsAMM.sUSD().balanceOf(address(this))); } emit Resolved(finalPrice, result, direction == result); } function isUserWinner() external view returns (bool) { return resolved && (direction == result); } modifier onlyAMM() { require(msg.sender == address(speedMarketsAMM), "only the AMM may perform these methods"); _; } event Resolved(int64 finalPrice, Direction result, bool userIsWinner); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // external import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; import "@openzeppelin/contracts-4.4.1/proxy/Clones.sol"; import "@pythnetwork/pyth-sdk-solidity/IPyth.sol"; import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol"; // internal import "../utils/proxy/solidity-0.8.0/ProxyReentrancyGuard.sol"; import "../utils/proxy/solidity-0.8.0/ProxyOwned.sol"; import "../utils/proxy/solidity-0.8.0/ProxyPausable.sol"; import "../utils/libraries/AddressSetLib.sol"; import "../interfaces/IStakingThales.sol"; import "../interfaces/IMultiCollateralOnOffRamp.sol"; import "../interfaces/IReferrals.sol"; import "../interfaces/IAddressManager.sol"; import "../interfaces/ISpeedMarketsAMM.sol"; import "./SpeedMarket.sol"; import "./SpeedMarketsAMMUtils.sol"; /// @title An AMM for Thales speed markets contract SpeedMarketsAMM is Initializable, ProxyOwned, ProxyPausable, ProxyReentrancyGuard { using SafeERC20Upgradeable for IERC20Upgradeable; using AddressSetLib for AddressSetLib.AddressSet; AddressSetLib.AddressSet internal _activeMarkets; AddressSetLib.AddressSet internal _maturedMarkets; uint private constant ONE = 1e18; uint private constant MAX_APPROVAL = type(uint256).max; IERC20Upgradeable public sUSD; address public speedMarketMastercopy; uint public safeBoxImpact; uint public lpFee; address private safeBox; // unused, moved to AddressManager mapping(bytes32 => bool) public supportedAsset; uint public minimalTimeToMaturity; uint public maximalTimeToMaturity; uint public minBuyinAmount; uint public maxBuyinAmount; mapping(bytes32 => uint) public maxRiskPerAsset; mapping(bytes32 => uint) public currentRiskPerAsset; mapping(bytes32 => bytes32) public assetToPythId; IPyth private pyth; // unused, moved to AddressManager uint64 public maximumPriceDelay; IStakingThales private stakingThales; // unused, moved to AddressManager mapping(address => AddressSetLib.AddressSet) internal _activeMarketsPerUser; mapping(address => AddressSetLib.AddressSet) internal _maturedMarketsPerUser; mapping(address => bool) public whitelistedAddresses; IMultiCollateralOnOffRamp private multiCollateralOnOffRamp; // unused, moved to AddressManager bool public multicollateralEnabled; mapping(bytes32 => mapping(SpeedMarket.Direction => uint)) public maxRiskPerAssetAndDirection; mapping(bytes32 => mapping(SpeedMarket.Direction => uint)) public currentRiskPerAssetAndDirection; uint64 public maximumPriceDelayForResolving; mapping(address => bool) public marketHasCreatedAtAttribute; address private referrals; // unused, moved to AddressManager uint[] public timeThresholdsForFees; uint[] public lpFees; SpeedMarketsAMMUtils private speedMarketsAMMUtils; mapping(address => bool) public marketHasFeeAttribute; /// @return The address of the address manager contract IAddressManager public addressManager; uint public maxSkewImpact; uint private constant SKEW_SLIPPAGE = 2e16; /// @param user user wallet address /// @param asset market asset /// @param strikeTime strike time, if zero delta time is used /// @param delta delta time, used if strike time is zero /// @param pythPrice structure with pyth price and publish time /// @param direction direction (UP/DOWN) /// @param collateral collateral address, for default collateral use zero address /// @param collateralAmount collateral amount, for non default includes fees /// @param referrer referrer address /// @param skewImpact skew impact, used to check skew slippage struct CreateMarketParams { address user; bytes32 asset; uint64 strikeTime; uint64 delta; PythStructs.Price pythPrice; SpeedMarket.Direction direction; address collateral; uint collateralAmount; address referrer; uint skewImpact; } receive() external payable {} function initialize(address _owner, IERC20Upgradeable _sUSD) external initializer { setOwner(_owner); initNonReentrant(); sUSD = _sUSD; } /// @notice create new market for a given delta/strike time /// @param _params parameters for creating market function createNewMarket(CreateMarketParams calldata _params) external payable nonReentrant notPaused onlyCreator { IAddressManager.Addresses memory contractsAddresses = addressManager.getAddresses(); bool isDefaultCollateral = _params.collateral == address(0); uint64 strikeTime = _params.strikeTime == 0 ? uint64(block.timestamp + _params.delta) : _params.strikeTime; uint buyinAmount = isDefaultCollateral ? _params.collateralAmount : _getBuyinWithConversion( _params.user, _params.collateral, _params.collateralAmount, strikeTime, contractsAddresses ); _createNewMarket( _params.user, _params.asset, strikeTime, _params.pythPrice, _params.direction, buyinAmount, isDefaultCollateral, _params.referrer, _params.skewImpact, contractsAddresses ); } function _getBuyinWithConversion( address user, address collateral, uint collateralAmount, uint64 strikeTime, IAddressManager.Addresses memory contractsAddresses ) internal returns (uint buyinAmount) { require(multicollateralEnabled, "Multicollateral onramp not enabled"); uint amountBefore = sUSD.balanceOf(address(this)); IMultiCollateralOnOffRamp iMultiCollateralOnOffRamp = IMultiCollateralOnOffRamp( contractsAddresses.multiCollateralOnOffRamp ); IERC20Upgradeable(collateral).safeTransferFrom(user, address(this), collateralAmount); IERC20Upgradeable(collateral).approve(address(iMultiCollateralOnOffRamp), collateralAmount); uint convertedAmount = iMultiCollateralOnOffRamp.onramp(collateral, collateralAmount); uint lpFeeForDeltaTime = speedMarketsAMMUtils.getFeeByTimeThreshold( uint64(strikeTime - block.timestamp), timeThresholdsForFees, lpFees, lpFee ); buyinAmount = (convertedAmount * ONE) / (ONE + safeBoxImpact + lpFeeForDeltaTime); uint amountDiff = sUSD.balanceOf(address(this)) - amountBefore; require(amountDiff >= buyinAmount, "not enough received via onramp"); } function _getSkewByAssetAndDirection(bytes32 _asset, SpeedMarket.Direction _direction) internal view returns (uint) { return (((currentRiskPerAssetAndDirection[_asset][_direction] * ONE) / maxRiskPerAssetAndDirection[_asset][_direction]) * maxSkewImpact) / ONE; } function _handleRiskAndGetFee( bytes32 asset, SpeedMarket.Direction direction, uint buyinAmount, uint64 strikeTime, uint skewImpact ) internal returns (uint lpFeeWithSkew) { uint skew = _getSkewByAssetAndDirection(asset, direction); require(skew <= skewImpact + SKEW_SLIPPAGE, "Skew slippage exceeded"); SpeedMarket.Direction oppositeDirection = direction == SpeedMarket.Direction.Up ? SpeedMarket.Direction.Down : SpeedMarket.Direction.Up; // calculate discount as half of skew for opposite direction uint discount = skew == 0 ? _getSkewByAssetAndDirection(asset, oppositeDirection) / 2 : 0; // decrease risk for opposite directionif there is, otherwise increase risk for current direction if (currentRiskPerAssetAndDirection[asset][oppositeDirection] > buyinAmount) { currentRiskPerAssetAndDirection[asset][oppositeDirection] -= buyinAmount; } else { currentRiskPerAssetAndDirection[asset][direction] += buyinAmount - currentRiskPerAssetAndDirection[asset][oppositeDirection]; currentRiskPerAssetAndDirection[asset][oppositeDirection] = 0; require( currentRiskPerAssetAndDirection[asset][direction] <= maxRiskPerAssetAndDirection[asset][direction], "Risk per direction exceeded" ); } // (LP fee by delta time) + (skew impact based on risk per direction and asset) - (discount as half of opposite skew) lpFeeWithSkew = speedMarketsAMMUtils.getFeeByTimeThreshold( uint64(strikeTime - block.timestamp), timeThresholdsForFees, lpFees, lpFee ) + skew - discount; currentRiskPerAsset[asset] += (buyinAmount * 2 - (buyinAmount * (ONE + lpFeeWithSkew)) / ONE); require(currentRiskPerAsset[asset] <= maxRiskPerAsset[asset], "Risk per asset exceeded"); } function _handleReferrerAndSafeBox( address user, address referrer, uint buyinAmount, IAddressManager.Addresses memory contractsAddresses ) internal returns (uint referrerShare) { IReferrals iReferrals = IReferrals(contractsAddresses.referrals); if (address(iReferrals) != address(0)) { address newOrExistingReferrer; if (referrer != address(0)) { iReferrals.setReferrer(referrer, user); newOrExistingReferrer = referrer; } else { newOrExistingReferrer = iReferrals.referrals(user); } if (newOrExistingReferrer != address(0)) { uint referrerFeeByTier = iReferrals.getReferrerFee(newOrExistingReferrer); if (referrerFeeByTier > 0) { referrerShare = (buyinAmount * referrerFeeByTier) / ONE; sUSD.safeTransfer(newOrExistingReferrer, referrerShare); emit ReferrerPaid(newOrExistingReferrer, user, referrerShare, buyinAmount); } } } sUSD.safeTransfer(contractsAddresses.safeBox, (buyinAmount * safeBoxImpact) / ONE - referrerShare); } function _createNewMarket( address user, bytes32 asset, uint64 strikeTime, PythStructs.Price calldata pythPrice, SpeedMarket.Direction direction, uint buyinAmount, bool transferSusd, address referrer, uint skewImpact, IAddressManager.Addresses memory contractsAddresses ) internal { require(supportedAsset[asset], "Asset is not supported"); require(buyinAmount >= minBuyinAmount && buyinAmount <= maxBuyinAmount, "Wrong buy in amount"); require(strikeTime >= (block.timestamp + minimalTimeToMaturity), "Strike time not alloowed"); require(strikeTime <= block.timestamp + maximalTimeToMaturity, "Time too far into the future"); uint lpFeeWithSkew = _handleRiskAndGetFee(asset, direction, buyinAmount, strikeTime, skewImpact); if (transferSusd) { uint totalAmountToTransfer = (buyinAmount * (ONE + safeBoxImpact + lpFeeWithSkew)) / ONE; sUSD.safeTransferFrom(user, address(this), totalAmountToTransfer); } SpeedMarket srm = SpeedMarket(Clones.clone(speedMarketMastercopy)); srm.initialize( SpeedMarket.InitParams( address(this), user, asset, strikeTime, pythPrice.price, uint64(pythPrice.publishTime), direction, buyinAmount, safeBoxImpact, lpFeeWithSkew ) ); sUSD.safeTransfer(address(srm), buyinAmount * 2); _handleReferrerAndSafeBox(user, referrer, buyinAmount, contractsAddresses); _activeMarkets.add(address(srm)); _activeMarketsPerUser[user].add(address(srm)); if (contractsAddresses.stakingThales != address(0)) { IStakingThales(contractsAddresses.stakingThales).updateVolume(user, buyinAmount); } marketHasCreatedAtAttribute[address(srm)] = true; marketHasFeeAttribute[address(srm)] = true; emit MarketCreated(address(srm), user, asset, strikeTime, pythPrice.price, direction, buyinAmount); emit MarketCreatedWithFees( address(srm), user, asset, strikeTime, pythPrice.price, direction, buyinAmount, safeBoxImpact, lpFeeWithSkew ); } /// @notice resolveMarket resolves an active market /// @param market address of the market function resolveMarket(address market, bytes[] calldata priceUpdateData) external payable nonReentrant notPaused { _resolveMarket(market, priceUpdateData); } /// @notice resolveMarket resolves an active market with offramp /// @param market address of the market function resolveMarketWithOfframp( address market, bytes[] calldata priceUpdateData, address collateral, bool toEth ) external payable nonReentrant notPaused { require(multicollateralEnabled, "Multicollateral offramp not enabled"); address user = SpeedMarket(market).user(); require(msg.sender == user, "Only allowed from market owner"); uint amountBefore = sUSD.balanceOf(user); _resolveMarket(market, priceUpdateData); uint amountDiff = sUSD.balanceOf(user) - amountBefore; sUSD.safeTransferFrom(user, address(this), amountDiff); if (amountDiff > 0) { IMultiCollateralOnOffRamp iMultiCollateralOnOffRamp = IMultiCollateralOnOffRamp( addressManager.multiCollateralOnOffRamp() ); if (toEth) { uint offramped = iMultiCollateralOnOffRamp.offrampIntoEth(amountDiff); address payable _to = payable(user); bool sent = _to.send(offramped); require(sent, "Failed to send Ether"); } else { uint offramped = iMultiCollateralOnOffRamp.offramp(collateral, amountDiff); IERC20Upgradeable(collateral).safeTransfer(user, offramped); } } } /// @notice resolveMarkets in a batch function resolveMarketsBatch(address[] calldata markets, bytes[] calldata priceUpdateData) external payable nonReentrant notPaused { for (uint i = 0; i < markets.length; i++) { if (canResolveMarket(markets[i])) { bytes[] memory subarray = new bytes[](1); subarray[0] = priceUpdateData[i]; _resolveMarket(markets[i], subarray); } } } function _resolveMarket(address market, bytes[] memory priceUpdateData) internal { require(canResolveMarket(market), "Can not resolve"); IPyth iPyth = IPyth(addressManager.pyth()); bytes32[] memory priceIds = new bytes32[](1); priceIds[0] = assetToPythId[SpeedMarket(market).asset()]; PythStructs.PriceFeed[] memory prices = iPyth.parsePriceFeedUpdates{value: iPyth.getUpdateFee(priceUpdateData)}( priceUpdateData, priceIds, SpeedMarket(market).strikeTime(), SpeedMarket(market).strikeTime() + maximumPriceDelayForResolving ); PythStructs.Price memory price = prices[0].price; require(price.price > 0, "Invalid price"); _resolveMarketWithPrice(market, price.price); } /// @notice admin resolve market for a given market address with finalPrice function resolveMarketManually(address _market, int64 _finalPrice) external isAddressWhitelisted { _resolveMarketManually(_market, _finalPrice); } /// @notice admin resolve for a given markets with finalPrices function resolveMarketManuallyBatch(address[] calldata markets, int64[] calldata finalPrices) external isAddressWhitelisted { for (uint i = 0; i < markets.length; i++) { if (canResolveMarket(markets[i])) { _resolveMarketManually(markets[i], finalPrices[i]); } } } /// @notice owner can resolve market for a given market address with finalPrice function resolveMarketAsOwner(address _market, int64 _finalPrice) external onlyOwner { require(canResolveMarket(_market), "Can not resolve"); _resolveMarketWithPrice(_market, _finalPrice); } function _resolveMarketManually(address _market, int64 _finalPrice) internal { SpeedMarket.Direction direction = SpeedMarket(_market).direction(); int64 strikePrice = SpeedMarket(_market).strikePrice(); bool isUserWinner = (_finalPrice < strikePrice && direction == SpeedMarket.Direction.Down) || (_finalPrice > strikePrice && direction == SpeedMarket.Direction.Up); require(canResolveMarket(_market) && !isUserWinner, "Can not resolve manually"); _resolveMarketWithPrice(_market, _finalPrice); } function _resolveMarketWithPrice(address market, int64 _finalPrice) internal { SpeedMarket(market).resolve(_finalPrice); _activeMarkets.remove(market); _maturedMarkets.add(market); address user = SpeedMarket(market).user(); if (_activeMarketsPerUser[user].contains(market)) { _activeMarketsPerUser[user].remove(market); } _maturedMarketsPerUser[user].add(market); bytes32 asset = SpeedMarket(market).asset(); uint buyinAmount = SpeedMarket(market).buyinAmount(); SpeedMarket.Direction direction = SpeedMarket(market).direction(); if (currentRiskPerAssetAndDirection[asset][direction] > buyinAmount) { currentRiskPerAssetAndDirection[asset][direction] -= buyinAmount; } else { currentRiskPerAssetAndDirection[asset][direction] = 0; } if (!SpeedMarket(market).isUserWinner()) { if (currentRiskPerAsset[asset] > 2 * buyinAmount) { currentRiskPerAsset[asset] -= (2 * buyinAmount); } else { currentRiskPerAsset[asset] = 0; } } emit MarketResolved(market, SpeedMarket(market).result(), SpeedMarket(market).isUserWinner()); } /// @notice Transfer amount to destination address function transferAmount(address _destination, uint _amount) external onlyOwner { sUSD.safeTransfer(_destination, _amount); emit AmountTransfered(_destination, _amount); } //////////// getters ///////////////// /// @notice activeMarkets returns list of active markets /// @param index index of the page /// @param pageSize number of addresses per page /// @return address[] active market list function activeMarkets(uint index, uint pageSize) external view returns (address[] memory) { return _activeMarkets.getPage(index, pageSize); } /// @notice maturedMarkets returns list of matured markets /// @param index index of the page /// @param pageSize number of addresses per page /// @return address[] matured market list function maturedMarkets(uint index, uint pageSize) external view returns (address[] memory) { return _maturedMarkets.getPage(index, pageSize); } /// @notice activeMarkets returns list of active markets per user function activeMarketsPerUser( uint index, uint pageSize, address user ) external view returns (address[] memory) { return _activeMarketsPerUser[user].getPage(index, pageSize); } /// @notice maturedMarkets returns list of matured markets per user function maturedMarketsPerUser( uint index, uint pageSize, address user ) external view returns (address[] memory) { return _maturedMarketsPerUser[user].getPage(index, pageSize); } /// @notice whether a market can be resolved function canResolveMarket(address market) public view returns (bool) { return _activeMarkets.contains(market) && (SpeedMarket(market).strikeTime() < block.timestamp) && !SpeedMarket(market).resolved(); } /// @notice get lengths of all arrays function getLengths(address user) external view returns (uint[5] memory) { return [ _activeMarkets.elements.length, _maturedMarkets.elements.length, _activeMarketsPerUser[user].elements.length, _maturedMarketsPerUser[user].elements.length, lpFees.length ]; } /// @notice get params for chained market function getParams(bytes32 asset) external view returns (ISpeedMarketsAMM.Params memory) { ISpeedMarketsAMM.Params memory params; params.supportedAsset = supportedAsset[asset]; params.safeBoxImpact = safeBoxImpact; params.maximumPriceDelay = maximumPriceDelay; return params; } //////////////////setters///////////////// /// @notice Set addresses used in AMM /// @param _mastercopy to use to create markets /// @param _speedMarketsAMMUtils address of speed markets AMM utils /// @param _addressManager address manager contract function setAMMAddresses( address _mastercopy, SpeedMarketsAMMUtils _speedMarketsAMMUtils, address _addressManager ) external onlyOwner { speedMarketMastercopy = _mastercopy; speedMarketsAMMUtils = _speedMarketsAMMUtils; addressManager = IAddressManager(_addressManager); emit AMMAddressesChanged(_mastercopy, _speedMarketsAMMUtils, _addressManager); } /// @notice Set parameters for limits function setLimitParams( uint _minBuyinAmount, uint _maxBuyinAmount, uint _minimalTimeToMaturity, uint _maximalTimeToMaturity, uint64 _maximumPriceDelay, uint64 _maximumPriceDelayForResolving ) external onlyOwner { minBuyinAmount = _minBuyinAmount; maxBuyinAmount = _maxBuyinAmount; minimalTimeToMaturity = _minimalTimeToMaturity; maximalTimeToMaturity = _maximalTimeToMaturity; maximumPriceDelay = _maximumPriceDelay; maximumPriceDelayForResolving = _maximumPriceDelayForResolving; emit LimitParamsChanged( _minBuyinAmount, _maxBuyinAmount, _minimalTimeToMaturity, _maximalTimeToMaturity, _maximumPriceDelay, _maximumPriceDelayForResolving ); } /// @notice maximum risk per asset and per asset and direction function setMaxRisks( bytes32 asset, uint _maxRiskPerAsset, uint _maxRiskPerAssetAndDirection ) external onlyOwner { maxRiskPerAsset[asset] = _maxRiskPerAsset; currentRiskPerAsset[asset] = 0; maxRiskPerAssetAndDirection[asset][SpeedMarket.Direction.Up] = _maxRiskPerAssetAndDirection; maxRiskPerAssetAndDirection[asset][SpeedMarket.Direction.Down] = _maxRiskPerAssetAndDirection; emit SetMaxRisks(asset, _maxRiskPerAsset, _maxRiskPerAssetAndDirection); } /// @notice set SafeBox and max skew impact /// @param _safeBoxImpact skew impact /// @param _maxSkewImpact skew impact function setSafeBoxAndMaxSkewImpact(uint _safeBoxImpact, uint _maxSkewImpact) external onlyOwner { safeBoxImpact = _safeBoxImpact; maxSkewImpact = _maxSkewImpact; emit SafeBoxAndMaxSkewImpactChanged(_safeBoxImpact, _maxSkewImpact); } /// @notice set LP fee params /// @param _timeThresholds array of time thresholds (minutes) for different fees in ascending order /// @param _lpFees array of fees applied to each time frame defined in _timeThresholds /// @param _lpFee default LP fee when there are no dynamic fees function setLPFeeParams( uint[] calldata _timeThresholds, uint[] calldata _lpFees, uint _lpFee ) external onlyOwner { require(_timeThresholds.length == _lpFees.length, "Times and fees must have the same length"); delete timeThresholdsForFees; delete lpFees; for (uint i = 0; i < _timeThresholds.length; i++) { timeThresholdsForFees.push(_timeThresholds[i]); lpFees.push(_lpFees[i]); } lpFee = _lpFee; emit SetLPFeeParams(_timeThresholds, _lpFees, _lpFee); } /// @notice set whether an asset is supported function setSupportedAsset(bytes32 asset, bool _supported) external onlyOwner { supportedAsset[asset] = _supported; emit SetSupportedAsset(asset, _supported); } /// @notice map asset to PythID, e.g. "ETH" as bytes 32 to an equivalent ID from pyth docs function setAssetToPythID(bytes32 asset, bytes32 pythId) external onlyOwner { assetToPythId[asset] = pythId; emit SetAssetToPythID(asset, pythId); } /// @notice set multi-collateral enabled function setMultiCollateralOnOffRampEnabled(bool _enabled) external onlyOwner { address multiCollateralAddress = addressManager.multiCollateralOnOffRamp(); if (multiCollateralAddress != address(0)) { sUSD.approve(multiCollateralAddress, _enabled ? MAX_APPROVAL : 0); } multicollateralEnabled = _enabled; emit MultiCollateralOnOffRampEnabled(_enabled); } /// @notice adding/removing whitelist address depending on a flag /// @param _whitelistAddress address that needed to be whitelisted/ ore removed from WL /// @param _flag adding or removing from whitelist (true: add, false: remove) function addToWhitelist(address _whitelistAddress, bool _flag) external onlyOwner { require(_whitelistAddress != address(0)); whitelistedAddresses[_whitelistAddress] = _flag; emit AddedIntoWhitelist(_whitelistAddress, _flag); } //////////////////modifiers///////////////// modifier isAddressWhitelisted() { require(whitelistedAddresses[msg.sender], "Resolver not whitelisted"); _; } modifier onlyCreator() { address speedMarketsCreator = addressManager.getAddress("SpeedMarketsAMMCreator"); require(msg.sender == speedMarketsCreator, "only from Creator"); _; } //////////////////events///////////////// event MarketCreated( address _market, address _user, bytes32 _asset, uint _strikeTime, int64 _strikePrice, SpeedMarket.Direction _direction, uint _buyinAmount ); event MarketCreatedWithFees( address _market, address _user, bytes32 _asset, uint _strikeTime, int64 _strikePrice, SpeedMarket.Direction _direction, uint _buyinAmount, uint _safeBoxImpact, uint _lpFee ); event MarketResolved(address _market, SpeedMarket.Direction _result, bool _userIsWinner); event AMMAddressesChanged(address _mastercopy, SpeedMarketsAMMUtils _speedMarketsAMMUtils, address _addressManager); event LimitParamsChanged( uint _minBuyinAmount, uint _maxBuyinAmount, uint _minimalTimeToMaturity, uint _maximalTimeToMaturity, uint _maximumPriceDelay, uint _maximumPriceDelayForResolving ); event SetMaxRisks(bytes32 asset, uint _maxRiskPerAsset, uint _maxRiskPerAssetAndDirection); event SafeBoxAndMaxSkewImpactChanged(uint _safeBoxImpact, uint _maxSkewImpact); event SetLPFeeParams(uint[] _timeThresholds, uint[] _lpFees, uint _lpFee); event SetSupportedAsset(bytes32 asset, bool _supported); event SetAssetToPythID(bytes32 asset, bytes32 pythId); event AddedIntoWhitelist(address _whitelistAddress, bool _flag); event MultiCollateralOnOffRampEnabled(bool _enabled); event ReferrerPaid(address refferer, address trader, uint amount, uint volume); event AmountTransfered(address _destination, uint _amount); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // external import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; import "@openzeppelin/contracts-4.4.1/proxy/Clones.sol"; import "@pythnetwork/pyth-sdk-solidity/IPyth.sol"; import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol"; // internal import "../utils/proxy/solidity-0.8.0/ProxyReentrancyGuard.sol"; import "../utils/proxy/solidity-0.8.0/ProxyOwned.sol"; import "../utils/proxy/solidity-0.8.0/ProxyPausable.sol"; import "../utils/libraries/AddressSetLib.sol"; import "../interfaces/IStakingThales.sol"; import "../interfaces/IMultiCollateralOnOffRamp.sol"; import "../interfaces/IReferrals.sol"; import "../interfaces/ISpeedMarketsAMM.sol"; import "../interfaces/IAddressManager.sol"; import "./SpeedMarket.sol"; import "./ChainedSpeedMarket.sol"; /// @title An AMM for Thales chained speed markets contract ChainedSpeedMarketsAMM is Initializable, ProxyOwned, ProxyPausable, ProxyReentrancyGuard { using SafeERC20Upgradeable for IERC20Upgradeable; using AddressSetLib for AddressSetLib.AddressSet; uint private constant ONE = 1e18; uint private constant MAX_APPROVAL = type(uint256).max; IERC20Upgradeable public sUSD; AddressSetLib.AddressSet internal _activeMarkets; AddressSetLib.AddressSet internal _maturedMarkets; mapping(address => AddressSetLib.AddressSet) internal _activeMarketsPerUser; mapping(address => AddressSetLib.AddressSet) internal _maturedMarketsPerUser; uint public minChainedMarkets; uint public maxChainedMarkets; uint64 public minTimeFrame; uint64 public maxTimeFrame; uint public minBuyinAmount; uint public maxBuyinAmount; uint public maxProfitPerIndividualMarket; uint private payoutMultiplier; // unused, part of payoutMultipliers uint public maxRisk; uint public currentRisk; address public chainedSpeedMarketMastercopy; bool public multicollateralEnabled; /// @notice The address of the address manager contract IAddressManager public addressManager; /// @notice payout multipliers for each number of chained markets, starting from minChainedMarkets up to maxChainedMarkets /// e.g. for 2-6 chained markets [1.7, 1.8, 1.9, 1.95, 2] - for 2 chained markets multiplier is 1.7, for 3 it is 1.8, ... uint[] public payoutMultipliers; // using this to solve stack too deep struct TempData { uint payout; uint payoutMultiplier; ISpeedMarketsAMM.Params speedAMMParams; } struct CreateMarketParams { address user; bytes32 asset; uint64 timeFrame; PythStructs.Price pythPrice; SpeedMarket.Direction[] directions; address collateral; uint collateralAmount; address referrer; } receive() external payable {} function initialize(address _owner, IERC20Upgradeable _sUSD) external initializer { setOwner(_owner); initNonReentrant(); sUSD = _sUSD; } function createNewMarket(CreateMarketParams calldata _params) external payable nonReentrant notPaused onlyPending { IAddressManager.Addresses memory contractsAddresses = addressManager.getAddresses(); bool isDefaultCollateral = _params.collateral == address(0); uint buyinAmount = isDefaultCollateral ? _params.collateralAmount : _getBuyinWithConversion(_params.user, _params.collateral, _params.collateralAmount, contractsAddresses); _createNewMarket( _params.user, _params.asset, _params.timeFrame, _params.pythPrice, _params.directions, buyinAmount, isDefaultCollateral, _params.referrer, contractsAddresses ); } function _getBuyinWithConversion( address user, address collateral, uint collateralAmount, IAddressManager.Addresses memory contractsAddresses ) internal returns (uint buyinAmount) { require(multicollateralEnabled, "Multicollateral onramp not enabled"); uint amountBefore = sUSD.balanceOf(address(this)); IMultiCollateralOnOffRamp multiCollateralOnOffRamp = IMultiCollateralOnOffRamp( contractsAddresses.multiCollateralOnOffRamp ); IERC20Upgradeable(collateral).safeTransferFrom(user, address(this), collateralAmount); IERC20Upgradeable(collateral).approve(address(multiCollateralOnOffRamp), collateralAmount); uint convertedAmount = multiCollateralOnOffRamp.onramp(collateral, collateralAmount); ISpeedMarketsAMM speedMarketsAMM = ISpeedMarketsAMM(contractsAddresses.speedMarketsAMM); buyinAmount = (convertedAmount * (ONE - speedMarketsAMM.safeBoxImpact())) / ONE; uint amountDiff = sUSD.balanceOf(address(this)) - amountBefore; require(amountDiff >= buyinAmount, "not enough received via onramp"); } function _getPayout( uint _buyinAmount, uint8 _numOfDirections, uint _payoutMultiplier ) internal pure returns (uint _payout) { _payout = _buyinAmount; for (uint8 i = 0; i < _numOfDirections; i++) { _payout = (_payout * _payoutMultiplier) / ONE; } } function _handleReferrerAndSafeBox( address user, address referrer, uint buyinAmount, uint safeBoxImpact, IAddressManager.Addresses memory contractsAddresses ) internal returns (uint referrerShare) { IReferrals referrals = IReferrals(contractsAddresses.referrals); if (address(referrals) != address(0)) { address newOrExistingReferrer; if (referrer != address(0)) { referrals.setReferrer(referrer, user); newOrExistingReferrer = referrer; } else { newOrExistingReferrer = referrals.referrals(user); } if (newOrExistingReferrer != address(0)) { uint referrerFeeByTier = referrals.getReferrerFee(newOrExistingReferrer); if (referrerFeeByTier > 0) { referrerShare = (buyinAmount * referrerFeeByTier) / ONE; sUSD.safeTransfer(newOrExistingReferrer, referrerShare); emit ReferrerPaid(newOrExistingReferrer, user, referrerShare, buyinAmount); } } } sUSD.safeTransfer(contractsAddresses.safeBox, (buyinAmount * safeBoxImpact) / ONE - referrerShare); } function _createNewMarket( address user, bytes32 asset, uint64 timeFrame, PythStructs.Price calldata pythPrice, SpeedMarket.Direction[] calldata directions, uint buyinAmount, bool transferSusd, address referrer, IAddressManager.Addresses memory contractsAddresses ) internal { TempData memory tempData; tempData.speedAMMParams = ISpeedMarketsAMM(contractsAddresses.speedMarketsAMM).getParams(asset); require(tempData.speedAMMParams.supportedAsset, "Asset is not supported"); require(buyinAmount >= minBuyinAmount && buyinAmount <= maxBuyinAmount, "Wrong buy in amount"); require(timeFrame >= minTimeFrame && timeFrame <= maxTimeFrame, "Wrong time frame"); require( directions.length >= minChainedMarkets && directions.length <= maxChainedMarkets, "Wrong number of directions" ); tempData.payoutMultiplier = payoutMultipliers[uint8(directions.length) - minChainedMarkets]; tempData.payout = _getPayout(buyinAmount, uint8(directions.length), tempData.payoutMultiplier); require(tempData.payout <= maxProfitPerIndividualMarket, "Profit too high"); currentRisk += (tempData.payout - buyinAmount); require(currentRisk <= maxRisk, "Out of liquidity"); if (transferSusd) { uint totalAmountToTransfer = (buyinAmount * (ONE + tempData.speedAMMParams.safeBoxImpact)) / ONE; sUSD.safeTransferFrom(user, address(this), totalAmountToTransfer); } ChainedSpeedMarket csm = ChainedSpeedMarket(Clones.clone(chainedSpeedMarketMastercopy)); csm.initialize( ChainedSpeedMarket.InitParams( address(this), user, asset, timeFrame, uint64(block.timestamp + timeFrame), uint64(block.timestamp + timeFrame * directions.length), // strike time pythPrice.price, directions, buyinAmount, tempData.speedAMMParams.safeBoxImpact, tempData.payoutMultiplier ) ); sUSD.safeTransfer(address(csm), tempData.payout); _handleReferrerAndSafeBox(user, referrer, buyinAmount, tempData.speedAMMParams.safeBoxImpact, contractsAddresses); _activeMarkets.add(address(csm)); _activeMarketsPerUser[user].add(address(csm)); if (contractsAddresses.stakingThales != address(0)) { IStakingThales(contractsAddresses.stakingThales).updateVolume(user, buyinAmount); } emit MarketCreated( address(csm), user, asset, timeFrame, uint64(block.timestamp + timeFrame * directions.length), // strike time pythPrice.price, directions, buyinAmount, tempData.payoutMultiplier, tempData.speedAMMParams.safeBoxImpact ); } /// @notice resolveMarket resolves an active market /// @param market address of the market function resolveMarket(address market, bytes[][] calldata priceUpdateData) external payable nonReentrant notPaused { _resolveMarket(market, priceUpdateData); } /// @notice resolveMarketWithOfframp resolves an active market with offramp /// @param market address of the market function resolveMarketWithOfframp( address market, bytes[][] calldata priceUpdateData, address collateral, bool toEth ) external payable nonReentrant notPaused { address user = ChainedSpeedMarket(market).user(); require(msg.sender == user, "Only allowed from market owner"); uint amountBefore = sUSD.balanceOf(user); _resolveMarket(market, priceUpdateData); uint amountDiff = sUSD.balanceOf(user) - amountBefore; sUSD.safeTransferFrom(user, address(this), amountDiff); if (amountDiff > 0) { IMultiCollateralOnOffRamp multiCollateralOnOffRamp = IMultiCollateralOnOffRamp( addressManager.multiCollateralOnOffRamp() ); if (toEth) { uint offramped = multiCollateralOnOffRamp.offrampIntoEth(amountDiff); address payable _to = payable(user); bool sent = _to.send(offramped); require(sent, "Failed to send Ether"); } else { uint offramped = multiCollateralOnOffRamp.offramp(collateral, amountDiff); IERC20Upgradeable(collateral).safeTransfer(user, offramped); } } } /// @notice resolveMarkets in a batch function resolveMarketsBatch(address[] calldata markets, bytes[][][] calldata priceUpdateData) external payable nonReentrant notPaused { for (uint i = 0; i < markets.length; i++) { if (canResolveMarket(markets[i])) { _resolveMarket(markets[i], priceUpdateData[i]); } } } function _resolveMarket(address market, bytes[][] memory priceUpdateData) internal { require(canResolveMarket(market), "Can not resolve"); IAddressManager.Addresses memory contractsAddresses = addressManager.getAddresses(); ISpeedMarketsAMM speedMarketsAMM = ISpeedMarketsAMM(contractsAddresses.speedMarketsAMM); bytes32[] memory priceIds = new bytes32[](1); priceIds[0] = speedMarketsAMM.assetToPythId(ChainedSpeedMarket(market).asset()); int64[] memory prices = new int64[](priceUpdateData.length); uint64 strikeTimePerDirection; for (uint i = 0; i < priceUpdateData.length; i++) { strikeTimePerDirection = ChainedSpeedMarket(market).initialStrikeTime() + uint64(i * ChainedSpeedMarket(market).timeFrame()); IPyth pyth = IPyth(contractsAddresses.pyth); PythStructs.PriceFeed[] memory pricesPerDirection = pyth.parsePriceFeedUpdates{ value: pyth.getUpdateFee(priceUpdateData[i]) }( priceUpdateData[i], priceIds, strikeTimePerDirection, strikeTimePerDirection + speedMarketsAMM.maximumPriceDelayForResolving() ); PythStructs.Price memory price = pricesPerDirection[0].price; require(price.price > 0, "invalid price"); prices[i] = price.price; } _resolveMarketWithPrices(market, prices, false); } /// @notice admin resolve market for a given market address with finalPrice function resolveMarketManually(address _market, int64[] calldata _finalPrices) external isAddressWhitelisted { _resolveMarketManually(_market, _finalPrices); } /// @notice admin resolve for a given markets with finalPrices function resolveMarketManuallyBatch(address[] calldata markets, int64[][] calldata finalPrices) external isAddressWhitelisted { for (uint i = 0; i < markets.length; i++) { if (canResolveMarket(markets[i])) { _resolveMarketManually(markets[i], finalPrices[i]); } } } function _resolveMarketManually(address _market, int64[] calldata _finalPrices) internal { require(canResolveMarket(_market), "Can not resolve"); _resolveMarketWithPrices(_market, _finalPrices, true); } /// @notice owner can resolve market for a given market address with finalPrices function resolveMarketAsOwner(address _market, int64[] calldata _finalPrices) external onlyOwner { require(canResolveMarket(_market), "Can not resolve"); _resolveMarketWithPrices(_market, _finalPrices, false); } function _resolveMarketWithPrices( address market, int64[] memory _finalPrices, bool _isManually ) internal { ChainedSpeedMarket(market).resolve(_finalPrices, _isManually); if (ChainedSpeedMarket(market).resolved()) { _activeMarkets.remove(market); _maturedMarkets.add(market); address user = ChainedSpeedMarket(market).user(); if (_activeMarketsPerUser[user].contains(market)) { _activeMarketsPerUser[user].remove(market); } _maturedMarketsPerUser[user].add(market); uint buyinAmount = ChainedSpeedMarket(market).buyinAmount(); uint payout = _getPayout( buyinAmount, ChainedSpeedMarket(market).numOfDirections(), ChainedSpeedMarket(market).payoutMultiplier() ); if (!ChainedSpeedMarket(market).isUserWinner()) { if (currentRisk > payout) { currentRisk -= payout; } else { currentRisk = 0; } } } emit MarketResolved(market, ChainedSpeedMarket(market).isUserWinner()); } /// @notice Transfer amount to destination address function transferAmount(address _destination, uint _amount) external onlyOwner { sUSD.safeTransfer(_destination, _amount); emit AmountTransfered(_destination, _amount); } //////////// getters ///////////////// /// @notice activeMarkets returns list of active markets /// @param index index of the page /// @param pageSize number of addresses per page /// @return address[] active market list function activeMarkets(uint index, uint pageSize) external view returns (address[] memory) { return _activeMarkets.getPage(index, pageSize); } /// @notice maturedMarkets returns list of matured markets /// @param index index of the page /// @param pageSize number of addresses per page /// @return address[] matured market list function maturedMarkets(uint index, uint pageSize) external view returns (address[] memory) { return _maturedMarkets.getPage(index, pageSize); } /// @notice activeMarkets returns list of active markets per user function activeMarketsPerUser( uint index, uint pageSize, address user ) external view returns (address[] memory) { return _activeMarketsPerUser[user].getPage(index, pageSize); } /// @notice maturedMarkets returns list of matured markets per user function maturedMarketsPerUser( uint index, uint pageSize, address user ) external view returns (address[] memory) { return _maturedMarketsPerUser[user].getPage(index, pageSize); } /// @notice whether a market can be resolved function canResolveMarket(address market) public view returns (bool) { return _activeMarkets.contains(market) && (ChainedSpeedMarket(market).initialStrikeTime() < block.timestamp) && !ChainedSpeedMarket(market).resolved(); } /// @notice get lengths of all arrays function getLengths(address user) external view returns (uint[4] memory) { return [ _activeMarkets.elements.length, _maturedMarkets.elements.length, _activeMarketsPerUser[user].elements.length, _maturedMarketsPerUser[user].elements.length ]; } //////////////////setters///////////////// /// @notice Set mastercopy to use to create markets /// @param _mastercopy to use to create markets function setMastercopy(address _mastercopy) external onlyOwner { chainedSpeedMarketMastercopy = _mastercopy; emit MastercopyChanged(_mastercopy); } /// @notice Set parameters for limits and payout function setLimitParams( uint64 _minTimeFrame, uint64 _maxTimeFrame, uint _minChainedMarkets, uint _maxChainedMarkets, uint _minBuyinAmount, uint _maxBuyinAmount, uint _maxProfitPerIndividualMarket, uint _maxRisk, uint[] calldata _payoutMultipliers ) external onlyOwner { require(_minChainedMarkets > 1, "min 2 chained markets"); minTimeFrame = _minTimeFrame; maxTimeFrame = _maxTimeFrame; minChainedMarkets = _minChainedMarkets; maxChainedMarkets = _maxChainedMarkets; minBuyinAmount = _minBuyinAmount; maxBuyinAmount = _maxBuyinAmount; maxProfitPerIndividualMarket = _maxProfitPerIndividualMarket; maxRisk = _maxRisk; payoutMultipliers = _payoutMultipliers; emit LimitParamsChanged( _minTimeFrame, _maxTimeFrame, _minChainedMarkets, _maxChainedMarkets, _minBuyinAmount, _maxBuyinAmount, _maxProfitPerIndividualMarket, _maxRisk, _payoutMultipliers ); } /// @notice set address manager contract address function setAddressManager(address _addressManager) external onlyOwner { addressManager = IAddressManager(_addressManager); emit AddressManagerChanged(_addressManager); } /// @notice set multicollateral enabled function setMultiCollateralOnOffRampEnabled(bool _enabled) external onlyOwner { address multiCollateralOnOffRamp = addressManager.multiCollateralOnOffRamp(); if (multiCollateralOnOffRamp != address(0)) { sUSD.approve(multiCollateralOnOffRamp, _enabled ? MAX_APPROVAL : 0); } multicollateralEnabled = _enabled; emit MultiCollateralOnOffRampEnabled(_enabled); } //////////////////modifiers///////////////// modifier isAddressWhitelisted() { ISpeedMarketsAMM speedMarketsAMM = ISpeedMarketsAMM(addressManager.speedMarketsAMM()); require(speedMarketsAMM.whitelistedAddresses(msg.sender), "Resolver not whitelisted"); _; } modifier onlyPending() { address speedMarketsCreator = addressManager.getAddress("SpeedMarketsAMMCreator"); require(msg.sender == speedMarketsCreator, "only from Creator"); _; } //////////////////events///////////////// event MarketCreated( address market, address user, bytes32 asset, uint64 timeFrame, uint64 strikeTime, int64 strikePrice, SpeedMarket.Direction[] directions, uint buyinAmount, uint payoutMultiplier, uint safeBoxImpact ); event MarketResolved(address market, bool userIsWinner); event MastercopyChanged(address mastercopy); event LimitParamsChanged( uint64 _minTimeFrame, uint64 _maxTimeFrame, uint _minChainedMarkets, uint _maxChainedMarkets, uint _minBuyinAmount, uint _maxBuyinAmount, uint _maxProfitPerIndividualMarket, uint _maxRisk, uint[] _payoutMultipliers ); event ReferrerPaid(address refferer, address trader, uint amount, uint volume); event MultiCollateralOnOffRampEnabled(bool _enabled); event AmountTransfered(address _destination, uint _amount); event AddressManagerChanged(address _addressManager); }
// 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: Apache-2.0 pragma solidity ^0.8.0; /// @title IPythEvents contains the events that Pyth contract emits. /// @dev This interface can be used for listening to the updates for off-chain and testing purposes. interface IPythEvents { /// @dev Emitted when the price feed with `id` has received a fresh update. /// @param id The Pyth Price Feed ID. /// @param publishTime Publish time of the given price update. /// @param price Price of the given price update. /// @param conf Confidence interval of the given price update. event PriceFeedUpdate( bytes32 indexed id, uint64 publishTime, int64 price, uint64 conf ); /// @dev Emitted when a batch price update is processed successfully. /// @param chainId ID of the source chain that the batch price update comes from. /// @param sequenceNumber Sequence number of the batch price update. event BatchPriceFeedUpdate(uint16 chainId, uint64 sequenceNumber); }
// 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 (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 (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library MathUpgradeable { /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a / b + (a % b == 0 ? 0 : 1); } }
// 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 (utils/math/SafeMath.sol) pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler * now has built in overflow checking. */ library SafeMathUpgradeable { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } }
// 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 // 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; library AddressSetLib { struct AddressSet { address[] elements; mapping(address => uint) indices; } function contains(AddressSet storage set, address candidate) internal view returns (bool) { if (set.elements.length == 0) { return false; } uint index = set.indices[candidate]; return index != 0 || set.elements[0] == candidate; } function getPage( AddressSet storage set, uint index, uint pageSize ) internal view returns (address[] memory) { // NOTE: This implementation should be converted to slice operators if the compiler is updated to v0.6.0+ uint endIndex = index + pageSize; // The check below that endIndex <= index handles overflow. // If the page extends past the end of the list, truncate it. if (endIndex > set.elements.length) { endIndex = set.elements.length; } if (endIndex <= index) { return new address[](0); } uint n = endIndex - index; // We already checked for negative overflow. address[] memory page = new address[](n); for (uint i; i < n; i++) { page[i] = set.elements[i + index]; } return page; } function add(AddressSet storage set, address element) internal { // Adding to a set is an idempotent operation. if (!contains(set, element)) { set.indices[element] = set.elements.length; set.elements.push(element); } } function remove(AddressSet storage set, address element) internal { require(contains(set, element), "Element not in set."); // Replace the removed element with the last element of the list. uint index = set.indices[element]; uint lastIndex = set.elements.length - 1; // We required that element is in the list, so it is not empty. if (index != lastIndex) { // No need to shift the last element if it is the one we want to delete. address shiftedElement = set.elements[lastIndex]; set.elements[index] = shiftedElement; set.indices[shiftedElement] = index; } set.elements.pop(); delete set.indices[element]; } }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; interface IStakingThales { function updateVolume(address account, uint amount) external; function updateStakingRewards( uint _currentPeriodRewards, uint _extraRewards, uint _revShare ) 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); function updateVolumeAtAmountDecimals( address account, uint amount, uint decimals ) external; }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; interface IMultiCollateralOnOffRamp { function onramp(address collateral, uint collateralAmount) external returns (uint); function onrampWithEth(uint amount) external payable returns (uint); function getMinimumReceived(address collateral, uint amount) external view returns (uint); function getMinimumNeeded(address collateral, uint amount) external view returns (uint); function WETH9() external view returns (address); function offrampIntoEth(uint amount) external returns (uint); function offramp(address collateral, uint amount) external returns (uint); function offrampFromIntoEth(address collateralFrom, uint amount) external returns (uint); function offrampFrom( address collateralFrom, address collateralTo, uint amount ) external returns (uint); function priceFeed() external view returns (address); }
// 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; /// @title An AMM utils for Thales speed markets contract SpeedMarketsAMMUtils { uint private constant SECONDS_PER_MINUTE = 60; /// @notice get dynamic fee based on defined time thresholds for a given delta time /// @param _deltaTimeSec to search for appropriate time range (in seconds) /// @param _timeThresholds array of time thresholds for each fee (in minutes) /// @param _fees array of fees for every time range /// @param _defaultFee if _deltaTime doesn't have appropriate time range return this value /// @return fee defined for specific time range to which _deltaTime belongs to function getFeeByTimeThreshold( uint64 _deltaTimeSec, uint[] calldata _timeThresholds, uint[] calldata _fees, uint _defaultFee ) external pure returns (uint fee) { fee = _defaultFee; uint _deltaTime = _deltaTimeSec / SECONDS_PER_MINUTE; for (uint i = _timeThresholds.length; i > 0; i--) { if (_deltaTime >= _timeThresholds[i - 1]) { fee = _fees[i - 1]; break; } } } }
// 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.8.0; // external import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; // internal import "../interfaces/IChainedSpeedMarketsAMM.sol"; import "./SpeedMarket.sol"; contract ChainedSpeedMarket { using SafeERC20Upgradeable for IERC20Upgradeable; struct InitParams { address _chainedMarketsAMM; address _user; bytes32 _asset; uint64 _timeFrame; uint64 _initialStrikeTime; uint64 _strikeTime; int64 _initialStrikePrice; SpeedMarket.Direction[] _directions; uint _buyinAmount; uint _safeBoxImpact; uint _payoutMultiplier; } address public user; bytes32 public asset; uint64 public timeFrame; uint64 public initialStrikeTime; uint64 public strikeTime; int64 public initialStrikePrice; int64[] public strikePrices; SpeedMarket.Direction[] public directions; uint public buyinAmount; uint public safeBoxImpact; uint public payoutMultiplier; bool public resolved; int64[] public finalPrices; bool public isUserWinner; uint256 public createdAt; IChainedSpeedMarketsAMM public chainedMarketsAMM; /* ========== CONSTRUCTOR ========== */ bool public initialized = false; function initialize(InitParams calldata params) external { require(!initialized, "Chained market already initialized"); initialized = true; chainedMarketsAMM = IChainedSpeedMarketsAMM(params._chainedMarketsAMM); user = params._user; asset = params._asset; timeFrame = params._timeFrame; initialStrikeTime = params._initialStrikeTime; strikeTime = params._strikeTime; initialStrikePrice = params._initialStrikePrice; directions = params._directions; buyinAmount = params._buyinAmount; safeBoxImpact = params._safeBoxImpact; payoutMultiplier = params._payoutMultiplier; chainedMarketsAMM.sUSD().approve(params._chainedMarketsAMM, type(uint256).max); createdAt = block.timestamp; } function resolve(int64[] calldata _finalPrices, bool _isManually) external onlyAMM { require(!resolved, "already resolved"); require(block.timestamp > initialStrikeTime + (timeFrame * (_finalPrices.length - 1)), "not ready to be resolved"); require(_finalPrices.length <= directions.length, "more prices than directions"); finalPrices = _finalPrices; for (uint i = 0; i < _finalPrices.length; i++) { strikePrices.push(i == 0 ? initialStrikePrice : _finalPrices[i - 1]); // previous final price is current strike price bool userLostDirection = _finalPrices[i] > 0 && strikePrices[i] > 0 && ((_finalPrices[i] >= strikePrices[i] && directions[i] == SpeedMarket.Direction.Down) || (_finalPrices[i] <= strikePrices[i] && directions[i] == SpeedMarket.Direction.Up)); // user lost stop checking rest of directions if (userLostDirection) { resolved = true; break; } // when last final price for last direction user won if (i == directions.length - 1) { require(!_isManually, "Can not resolve manually"); isUserWinner = true; resolved = true; } } require(resolved, "Not ready to resolve"); if (isUserWinner) { chainedMarketsAMM.sUSD().safeTransfer(user, chainedMarketsAMM.sUSD().balanceOf(address(this))); } else { chainedMarketsAMM.sUSD().safeTransfer( address(chainedMarketsAMM), chainedMarketsAMM.sUSD().balanceOf(address(this)) ); } emit Resolved(finalPrices, isUserWinner); } /// @notice numOfDirections returns number of directions (speed markets in chain) /// @return uint8 function numOfDirections() external view returns (uint8) { return uint8(directions.length); } /// @notice numOfPrices returns number of strike/finales /// @return uint function numOfPrices() external view returns (uint) { return strikePrices.length; } modifier onlyAMM() { require(msg.sender == address(chainedMarketsAMM), "only the AMM may perform these methods"); _; } event Resolved(int64[] finalPrices, bool userIsWinner); }
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract ABI
API[{"anonymous":false,"inputs":[{"components":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bytes32","name":"asset","type":"bytes32"},{"internalType":"uint64","name":"timeFrame","type":"uint64"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"uint256","name":"strikePriceSlippage","type":"uint256"},{"internalType":"enum SpeedMarket.Direction[]","name":"directions","type":"uint8[]"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"buyinAmount","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"},{"internalType":"uint256","name":"createdAt","type":"uint256"}],"indexed":false,"internalType":"struct SpeedMarketsAMMCreator.PendingChainedSpeedMarket","name":"_pendingChainedSpeedMarket","type":"tuple"}],"name":"AddChainedSpeedMarket","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bytes32","name":"asset","type":"bytes32"},{"internalType":"uint64","name":"strikeTime","type":"uint64"},{"internalType":"uint64","name":"delta","type":"uint64"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"uint256","name":"strikePriceSlippage","type":"uint256"},{"internalType":"enum SpeedMarket.Direction","name":"direction","type":"uint8"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"buyinAmount","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"},{"internalType":"uint256","name":"skewImpact","type":"uint256"},{"internalType":"uint256","name":"createdAt","type":"uint256"}],"indexed":false,"internalType":"struct SpeedMarketsAMMCreator.PendingSpeedMarket","name":"_pendingSpeedMarket","type":"tuple"}],"name":"AddSpeedMarket","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_pendingSize","type":"uint256"},{"indexed":false,"internalType":"uint8","name":"_createdSize","type":"uint8"}],"name":"CreateSpeedMarkets","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"_errorMessage","type":"string"},{"components":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bytes32","name":"asset","type":"bytes32"},{"internalType":"uint64","name":"timeFrame","type":"uint64"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"uint256","name":"strikePriceSlippage","type":"uint256"},{"internalType":"enum SpeedMarket.Direction[]","name":"directions","type":"uint8[]"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"buyinAmount","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"},{"internalType":"uint256","name":"createdAt","type":"uint256"}],"indexed":false,"internalType":"struct SpeedMarketsAMMCreator.PendingChainedSpeedMarket","name":"_pendingChainedSpeedMarket","type":"tuple"}],"name":"LogChainedError","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"_data","type":"bytes"},{"components":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bytes32","name":"asset","type":"bytes32"},{"internalType":"uint64","name":"timeFrame","type":"uint64"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"uint256","name":"strikePriceSlippage","type":"uint256"},{"internalType":"enum SpeedMarket.Direction[]","name":"directions","type":"uint8[]"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"buyinAmount","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"},{"internalType":"uint256","name":"createdAt","type":"uint256"}],"indexed":false,"internalType":"struct SpeedMarketsAMMCreator.PendingChainedSpeedMarket","name":"_pendingChainedSpeedMarket","type":"tuple"}],"name":"LogChainedErrorData","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"_errorMessage","type":"string"},{"components":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bytes32","name":"asset","type":"bytes32"},{"internalType":"uint64","name":"strikeTime","type":"uint64"},{"internalType":"uint64","name":"delta","type":"uint64"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"uint256","name":"strikePriceSlippage","type":"uint256"},{"internalType":"enum SpeedMarket.Direction","name":"direction","type":"uint8"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"buyinAmount","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"},{"internalType":"uint256","name":"skewImpact","type":"uint256"},{"internalType":"uint256","name":"createdAt","type":"uint256"}],"indexed":false,"internalType":"struct SpeedMarketsAMMCreator.PendingSpeedMarket","name":"_pendingSpeedMarket","type":"tuple"}],"name":"LogError","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"_data","type":"bytes"},{"components":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bytes32","name":"asset","type":"bytes32"},{"internalType":"uint64","name":"strikeTime","type":"uint64"},{"internalType":"uint64","name":"delta","type":"uint64"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"uint256","name":"strikePriceSlippage","type":"uint256"},{"internalType":"enum SpeedMarket.Direction","name":"direction","type":"uint8"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"buyinAmount","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"},{"internalType":"uint256","name":"skewImpact","type":"uint256"},{"internalType":"uint256","name":"createdAt","type":"uint256"}],"indexed":false,"internalType":"struct SpeedMarketsAMMCreator.PendingSpeedMarket","name":"_pendingSpeedMarket","type":"tuple"}],"name":"LogErrorData","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerNominated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"isPaused","type":"bool"}],"name":"PauseChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_addressManager","type":"address"}],"name":"SetAddressManager","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"_maxCreationDelay","type":"uint64"}],"name":"SetMaxCreationDelay","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes32","name":"asset","type":"bytes32"},{"internalType":"uint64","name":"timeFrame","type":"uint64"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"uint256","name":"strikePriceSlippage","type":"uint256"},{"internalType":"enum SpeedMarket.Direction[]","name":"directions","type":"uint8[]"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"buyinAmount","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"}],"internalType":"struct SpeedMarketsAMMCreator.ChainedSpeedMarketParams","name":"_params","type":"tuple"}],"name":"addPendingChainedSpeedMarket","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes32","name":"asset","type":"bytes32"},{"internalType":"uint64","name":"strikeTime","type":"uint64"},{"internalType":"uint64","name":"delta","type":"uint64"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"uint256","name":"strikePriceSlippage","type":"uint256"},{"internalType":"enum SpeedMarket.Direction","name":"direction","type":"uint8"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"buyinAmount","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"},{"internalType":"uint256","name":"skewImpact","type":"uint256"}],"internalType":"struct SpeedMarketsAMMCreator.SpeedMarketParams","name":"_params","type":"tuple"}],"name":"addPendingSpeedMarket","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"addressManager","outputs":[{"internalType":"contract IAddressManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"bytes32","name":"asset","type":"bytes32"},{"internalType":"uint64","name":"timeFrame","type":"uint64"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"uint256","name":"strikePriceSlippage","type":"uint256"},{"internalType":"enum SpeedMarket.Direction[]","name":"directions","type":"uint8[]"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"buyinAmount","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"}],"internalType":"struct SpeedMarketsAMMCreator.ChainedSpeedMarketParams","name":"_chainedMarketParams","type":"tuple"},{"internalType":"bytes[]","name":"_priceUpdateData","type":"bytes[]"}],"name":"createChainedSpeedMarket","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"_priceUpdateData","type":"bytes[]"}],"name":"createFromPendingChainedSpeedMarkets","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"_priceUpdateData","type":"bytes[]"}],"name":"createFromPendingSpeedMarkets","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes32","name":"asset","type":"bytes32"},{"internalType":"uint64","name":"strikeTime","type":"uint64"},{"internalType":"uint64","name":"delta","type":"uint64"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"uint256","name":"strikePriceSlippage","type":"uint256"},{"internalType":"enum SpeedMarket.Direction","name":"direction","type":"uint8"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"buyinAmount","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"},{"internalType":"uint256","name":"skewImpact","type":"uint256"}],"internalType":"struct SpeedMarketsAMMCreator.SpeedMarketParams","name":"_speedMarketParams","type":"tuple"},{"internalType":"bytes[]","name":"_priceUpdateData","type":"bytes[]"}],"name":"createSpeedMarket","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getPendingChainedSpeedMarketsSize","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPendingSpeedMarketsSize","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initNonReentrant","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_addressManager","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastPauseTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxCreationDelay","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"nominateNewOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nominatedOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"pendingChainedSpeedMarkets","outputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bytes32","name":"asset","type":"bytes32"},{"internalType":"uint64","name":"timeFrame","type":"uint64"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"uint256","name":"strikePriceSlippage","type":"uint256"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"buyinAmount","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"},{"internalType":"uint256","name":"createdAt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"pendingSpeedMarkets","outputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bytes32","name":"asset","type":"bytes32"},{"internalType":"uint64","name":"strikeTime","type":"uint64"},{"internalType":"uint64","name":"delta","type":"uint64"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"uint256","name":"strikePriceSlippage","type":"uint256"},{"internalType":"enum SpeedMarket.Direction","name":"direction","type":"uint8"},{"internalType":"address","name":"collateral","type":"address"},{"internalType":"uint256","name":"buyinAmount","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"},{"internalType":"uint256","name":"skewImpact","type":"uint256"},{"internalType":"uint256","name":"createdAt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_addressManager","type":"address"}],"name":"setAddressManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"_maxCreationDelay","type":"uint64"}],"name":"setMaxCreationDelay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_paused","type":"bool"}],"name":"setPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"proxyAddress","type":"address"}],"name":"transferOwnershipAtInit","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
608060405234801561001057600080fd5b506136e7806100206000396000f3fe6080604052600436106101665760003560e01c806353a47bb7116100d15780638d2ccac71161008a578063ad043f2d11610064578063ad043f2d14610489578063c3b83f5f1461049c578063ebc79772146104bc578063f6264e75146104d157600080fd5b80638d2ccac71461043a5780638da5cb5b1461044d57806391b4ded91461047357600080fd5b806353a47bb7146102fc5780635c975abb1461031c5780636032a02714610346578063766f924a1461036657806379ba5097146103a35780638411f183146103b857600080fd5b80631c07d3c3116101235780631c07d3c314610231578063214e72cb146102695780632a789dc41461027c5780632e8eedd5146102915780633ab76e9f146102a4578063485cc955146102dc57600080fd5b80630652b57a1461016b57806313af40351461018d5780631627540c146101ad57806316c38b3c146101cd57806319297361146101ed5780631936f21c14610211575b600080fd5b34801561017757600080fd5b5061018b610186366004612a9f565b6104f1565b005b34801561019957600080fd5b5061018b6101a8366004612a9f565b61054e565b3480156101b957600080fd5b5061018b6101c8366004612a9f565b610687565b3480156101d957600080fd5b5061018b6101e8366004612b55565b6106dd565b3480156101f957600080fd5b506006545b6040519081526020015b60405180910390f35b34801561021d57600080fd5b5061018b61022c366004612c5f565b610753565b34801561023d57600080fd5b5061025161024c366004612df4565b610a7f565b6040516102089c9b9a9998979695949392919061309b565b61018b610277366004612b16565b610b0d565b34801561028857600080fd5b506007546101fe565b61018b61029f366004612dae565b61113a565b3480156102b057600080fd5b506008546102c4906001600160a01b031681565b6040516001600160a01b039091168152602001610208565b3480156102e857600080fd5b5061018b6102f7366004612ade565b611430565b34801561030857600080fd5b506001546102c4906001600160a01b031681565b34801561032857600080fd5b506003546103369060ff1681565b6040519015158152602001610208565b34801561035257600080fd5b5061018b610361366004612d92565b61150e565b34801561037257600080fd5b5060055461038b9061010090046001600160401b031681565b6040516001600160401b039091168152602001610208565b3480156103af57600080fd5b5061018b611875565b3480156103c457600080fd5b506103d86103d3366004612df4565b611972565b604080516001600160a01b039a8b16815260208101999099526001600160401b039097169688019690965260608701949094526080860192909252851660a085015260c08401529290921660e082015261010081019190915261012001610208565b61018b610448366004612c99565b6119e8565b34801561045957600080fd5b506000546102c4906201000090046001600160a01b031681565b34801561047f57600080fd5b506101fe60025481565b61018b610497366004612b16565b611d08565b3480156104a857600080fd5b5061018b6104b7366004612a9f565b612254565b3480156104c857600080fd5b5061018b61236d565b3480156104dd57600080fd5b5061018b6104ec366004612e0c565b6123cb565b6104f961242a565b600880546001600160a01b0319166001600160a01b0383169081179091556040519081527f954328d28753080b3c499697bde218fd8b53e924669801835383aa346e6940ee906020015b60405180910390a150565b6001600160a01b0381166105a95760405162461bcd60e51b815260206004820152601960248201527f4f776e657220616464726573732063616e6e6f7420626520300000000000000060448201526064015b60405180910390fd5b600154600160a01b900460ff16156106155760405162461bcd60e51b815260206004820152602960248201527f416c726561647920696e697469616c697a65642c20757365206e6f6d696e617460448201526832a732bba7bbb732b960b91b60648201526084016105a0565b6001805460ff60a01b1916600160a01b179055600080546001600160a01b03831662010000810262010000600160b01b03199092169190911782556040805192835260208301919091527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9101610543565b61068f61242a565b600180546001600160a01b0319166001600160a01b0383169081179091556040519081527f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce2290602001610543565b6106e561242a565b60035460ff16151581151514156106f95750565b6003805460ff191682151590811790915560ff161561071757426002555b60035460405160ff909116151581527f8fb6c181ee25a520cf3dd6565006ef91229fcfe5a989566c2a3b8c115570cec590602001610543565b50565b6001600460008282546107669190613508565b909155505060045460035460ff16156107915760405162461bcd60e51b81526004016105a09061323b565b6000604051806101400160405280336001600160a01b03168152602001846000013581526020018460200160208101906107cb9190612e0c565b6001600160401b0316815260200184604001358152602001846060013581526020018480608001906107fd91906134c1565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050509082525060200161084460c0860160a08701612a9f565b6001600160a01b0316815260c0850135602082015260400161086d610100860160e08701612a9f565b6001600160a01b039081168252426020928301526007805460018101825560009190915283517fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c688600a90920291820180546001600160a01b03191691909316178255838301517fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68982015560408401517fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68a8201805467ffffffffffffffff19166001600160401b0390921691909117905560608401517fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68b82015560808401517fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68c82015560a08401518051949550859492936109ce937fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68d909301929101906127de565b5060c08201516006820180546001600160a01b039283166001600160a01b03199182161790915560e08401516007840155610100840151600884018054919093169116179055610120909101516009909101556040517f099eb78f69f1559bb54045718ce32bd1bcca14c366705ae70449b9ccf154623690610a51908390613499565b60405180910390a1506004548114610a7b5760405162461bcd60e51b81526004016105a090613298565b5050565b60068181548110610a8f57600080fd5b60009182526020909120600a909102018054600182015460028301546003840154600485015460058601546006870154600788015460088901546009909901546001600160a01b039889169a5096986001600160401b0380881699600160401b90980416979596949560ff851695610100909504851694909216918c565b600160046000828254610b209190613508565b909155505060045460035460ff1615610b4b5760405162461bcd60e51b81526004016105a09061323b565b600754610b8f5760405162461bcd60e51b81526020600482015260126024820152714e6f2070656e64696e67206d61726b65747360701b60448201526064016105a0565b81610bac5760405162461bcd60e51b81526004016105a090613204565b600854604080516351cfd60960e11b815290516000926001600160a01b03169163a39fac129160048083019260c0929190829003018186803b158015610bf157600080fd5b505afa158015610c05573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c299190612bac565b9050610c3a816080015185856124a4565b60008160a0015190506000816001600160a01b031663a201b3076040518163ffffffff1660e01b815260040160206040518083038186803b158015610c7e57600080fd5b505afa158015610c92573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cb69190612e28565b90506000805b60075460ff821610156110c357600060078260ff1681548110610cef57634e487b7160e01b600052603260045260246000fd5b60009182526020918290206040805161014081018252600a90930290910180546001600160a01b0316835260018101548385015260028101546001600160401b03168383015260038101546060840152600481015460808401526005810180548351818702810187019094528084529394919360a086019392830182828015610dd557602002820191906000526020600020906000905b82829054906101000a900460ff166001811115610db357634e487b7160e01b600052602160045260246000fd5b815260206001928301818104948501949093039092029101808411610d865790505b505050918352505060068201546001600160a01b0390811660208301526007830154604083015260088301541660608201526009909101546080909101526005546101208201519192504291610e399161010090046001600160401b031690613508565b11610e4457506110b1565b6000610e5f8783602001518785606001518660800151612583565b60085460405163bf40fac160e01b8152602060048201526016602482015275436861696e656453706565644d61726b657473414d4d60501b60448201529192506001600160a01b03169063bf40fac19060640160206040518083038186803b158015610eca57600080fd5b505afa158015610ede573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f029190612ac2565b6001600160a01b0316630bfd50ce60405180610100016040528085600001516001600160a01b031681526020018560200151815260200185604001516001600160401b031681526020018481526020018560a0015181526020018560c001516001600160a01b031681526020018560e0015181526020018561010001516001600160a01b03168152506040518263ffffffff1660e01b8152600401610fa791906132cf565b600060405180830381600087803b158015610fc157600080fd5b505af1925050508015610fd2575060015b6110a057610fde6135e6565b806308c379a0141561103d5750610ff36135fe565b80610ffe575061103f565b7fe84e33c8088d8797d0968617fc974690124648a9fe6f643c976dbaa434e86c4e818460405161102f9291906131b2565b60405180910390a1506110ae565b505b3d808015611069576040519150601f19603f3d011682016040523d82523d6000602084013e61106e565b606091505b507fea71beab728aa700f4b1b124c203ca9981b99696ed9f56b3def56a1b3a138332818460405161102f9291906131b2565b836110aa816135b0565b9450505b50505b806110bb816135b0565b915050610cbc565b5060078054906110d49060006128a0565b6040805182815260ff841660208201527f48be52c64e0a5ff7b386f592283a0ee5b473efc8a04c47cca0e942d90574d376910160405180910390a1505050505060045481146111355760405162461bcd60e51b81526004016105a090613298565b505050565b60016004600082825461114d9190613508565b909155505060045460035460ff16156111785760405162461bcd60e51b81526004016105a09061323b565b816111955760405162461bcd60e51b81526004016105a090613204565b600854604080516351cfd60960e11b815290516000926001600160a01b03169163a39fac129160048083019260c0929190829003018186803b1580156111da57600080fd5b505afa1580156111ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112129190612bac565b9050611223816080015185856124a4565b60008160a00151905060006112b7838860000135846001600160a01b031663a201b3076040518163ffffffff1660e01b815260040160206040518083038186803b15801561127057600080fd5b505afa158015611284573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112a89190612e28565b8a606001358b60800135612583565b9050816001600160a01b031663e0223eea604051806101400160405280336001600160a01b031681526020018a6000013581526020018a60200160208101906113009190612e0c565b6001600160401b0316815260200161131e60608c0160408d01612e0c565b6001600160401b031681526020810185905260400161134360c08c0160a08d01612b8d565b600181111561136257634e487b7160e01b600052602160045260246000fd5b815260200161137760e08c0160c08d01612a9f565b6001600160a01b0316815260e08b013560208201526040016113a16101208c016101008d01612a9f565b6001600160a01b031681526020018a61012001358152506040518263ffffffff1660e01b81526004016113d491906133a1565b600060405180830381600087803b1580156113ee57600080fd5b505af1158015611402573d6000803e3d6000fd5b50505050505050600454811461142a5760405162461bcd60e51b81526004016105a090613298565b50505050565b600054610100900460ff1661144b5760005460ff161561144f565b303b155b6114b25760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016105a0565b600054610100900460ff161580156114d4576000805461ffff19166101011790555b6114dd8361054e565b600880546001600160a01b0319166001600160a01b0384161790558015611135576000805461ff0019169055505050565b6001600460008282546115219190613508565b909155505060045460035460ff161561154c5760405162461bcd60e51b81526004016105a09061323b565b6000604051806101800160405280336001600160a01b03168152602001846000013581526020018460200160208101906115869190612e0c565b6001600160401b031681526020016115a46060860160408701612e0c565b6001600160401b03168152606080860135602083015260808601356040830152016115d560c0860160a08701612b8d565b60018111156115f457634e487b7160e01b600052602160045260246000fd5b815260200161160960e0860160c08701612a9f565b6001600160a01b0316815260e0850135602082015260400161163361012086016101008701612a9f565b6001600160a01b0390811682526101208601356020808401919091524260409384015260068054600181810183556000929092528551600a9091027ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f81018054929095166001600160a01b0319909216919091178455918501517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d40830155928401517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d418201805460608701516001600160401b03908116600160401b026001600160801b031990921693169290921791909117905560808401517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d4282015560a08401517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d4382015560c08401517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d449091018054949550859492939192909160ff199091169083818111156117d657634e487b7160e01b600052602160045260246000fd5b021790555060e0820151600582018054610100600160a81b0319166101006001600160a01b0393841681029190911790915583015160068301556101208301516007830180546001600160a01b031916919092161790556101408201516008820155610160909101516009909101556040517faa9b85a2e5b93e844f4da51afaa437f075601edf0a59b74db14929d59e2d797790610a519083906134ac565b6001546001600160a01b031633146118ed5760405162461bcd60e51b815260206004820152603560248201527f596f75206d757374206265206e6f6d696e61746564206265666f726520796f7560448201527402063616e20616363657074206f776e65727368697605c1b60648201526084016105a0565b60005460015460408051620100009093046001600160a01b03908116845290911660208301527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c910160405180910390a1600180546000805462010000600160b01b0319166001600160a01b03831662010000021790556001600160a01b0319169055565b6007818154811061198257600080fd5b60009182526020909120600a90910201805460018201546002830154600384015460048501546006860154600787015460088801546009909801546001600160a01b03978816995095976001600160401b03909516969395929491841693909291169089565b6001600460008282546119fb9190613508565b909155505060045460035460ff1615611a265760405162461bcd60e51b81526004016105a09061323b565b81611a435760405162461bcd60e51b81526004016105a090613204565b600854604080516351cfd60960e11b815290516000926001600160a01b03169163a39fac129160048083019260c0929190829003018186803b158015611a8857600080fd5b505afa158015611a9c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ac09190612bac565b9050611ad1816080015185856124a4565b60008160a0015190506000611b65838860000135846001600160a01b031663a201b3076040518163ffffffff1660e01b815260040160206040518083038186803b158015611b1e57600080fd5b505afa158015611b32573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b569190612e28565b8a604001358b60600135612583565b60085460405163bf40fac160e01b8152602060048201526016602482015275436861696e656453706565644d61726b657473414d4d60501b60448201529192506001600160a01b03169063bf40fac19060640160206040518083038186803b158015611bd057600080fd5b505afa158015611be4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c089190612ac2565b6001600160a01b0316630bfd50ce604051806101000160405280336001600160a01b031681526020018a6000013581526020018a6020016020810190611c4e9190612e0c565b6001600160401b0316815260208101859052604001611c7060808c018c6134c1565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602001611cb760c08c0160a08d01612a9f565b6001600160a01b0316815260c08b01356020820152604001611ce06101008c0160e08d01612a9f565b6001600160a01b03168152506040518263ffffffff1660e01b81526004016113d491906132cf565b600160046000828254611d1b9190613508565b909155505060045460035460ff1615611d465760405162461bcd60e51b81526004016105a09061323b565b600654611d8a5760405162461bcd60e51b81526020600482015260126024820152714e6f2070656e64696e67206d61726b65747360701b60448201526064016105a0565b81611da75760405162461bcd60e51b81526004016105a090613204565b600854604080516351cfd60960e11b815290516000926001600160a01b03169163a39fac129160048083019260c0929190829003018186803b158015611dec57600080fd5b505afa158015611e00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e249190612bac565b9050611e35816080015185856124a4565b60008160a0015190506000816001600160a01b031663a201b3076040518163ffffffff1660e01b815260040160206040518083038186803b158015611e7957600080fd5b505afa158015611e8d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611eb19190612e28565b90506000805b60065460ff8216101561224357600060068260ff1681548110611eea57634e487b7160e01b600052603260045260246000fd5b60009182526020918290206040805161018081018252600a90930290910180546001600160a01b031683526001808201549484019490945260028101546001600160401b0380821693850193909352600160401b9004909116606083015260038101546080830152600481015460a083015260058101549192909160c084019160ff90911690811115611f8d57634e487b7160e01b600052602160045260246000fd5b6001811115611fac57634e487b7160e01b600052602160045260246000fd5b8152600582810154610100908190046001600160a01b0390811660208501526006850154604085015260078501541660608401526008840154608084015260099093015460a09092019190915254610160830151929350429261201b929091046001600160401b031690613508565b116120265750612231565b60006120418783602001518785608001518660a00151612583565b9050856001600160a01b031663e0223eea60405180610140016040528085600001516001600160a01b031681526020018560200151815260200185604001516001600160401b0316815260200185606001516001600160401b031681526020018481526020018560c0015160018111156120cb57634e487b7160e01b600052602160045260246000fd5b81526020018560e001516001600160a01b0316815260200185610100015181526020018561012001516001600160a01b031681526020018561014001518152506040518263ffffffff1660e01b815260040161212791906133a1565b600060405180830381600087803b15801561214157600080fd5b505af1925050508015612152575060015b6122205761215e6135e6565b806308c379a014156121bd57506121736135fe565b8061217e57506121bf565b7f07f812267f276d6fcc4b3a3d1f2797c3455cdc13d47462b1567a849842e13c4681846040516121af9291906131e0565b60405180910390a15061222e565b505b3d8080156121e9576040519150601f19603f3d011682016040523d82523d6000602084013e6121ee565b606091505b507faf05d7cd9581ee93ea4340706c133f4b6b0bc1f1a71b7fbcdd2dccc025e6d5bd81846040516121af9291906131e0565b8361222a816135b0565b9450505b50505b8061223b816135b0565b915050611eb7565b5060068054906110d49060006128c1565b61225c61242a565b6001600160a01b0381166122a45760405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b60448201526064016105a0565b600154600160a81b900460ff16156122f45760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481d1c985b9cd9995c9c9959606a1b60448201526064016105a0565b600080546001600160a01b038381166201000081810262010000600160b01b031990941693909317938490556001805460ff60a81b1916600160a81b1790556040805193909404909116825260208201527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9101610543565b60055460ff16156123b65760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b60448201526064016105a0565b6005805460ff19166001908117909155600455565b6123d361242a565b6005805468ffffffffffffffff0019166101006001600160401b038416908102919091179091556040519081527f41b95b0cd63e823b0fff2701a35e7ab970829374fa79149ca1b1d1dce73e001890602001610543565b6000546201000090046001600160a01b031633146124a25760405162461bcd60e51b815260206004820152602f60248201527f4f6e6c792074686520636f6e7472616374206f776e6572206d6179207065726660448201526e37b936903a3434b99030b1ba34b7b760891b60648201526084016105a0565b565b60405163d47eed4560e01b815283906001600160a01b0382169063ef9e5e2890829063d47eed45906124dc908890889060040161311b565b60206040518083038186803b1580156124f457600080fd5b505afa158015612508573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061252c9190612b75565b85856040518463ffffffff1660e01b815260040161254b92919061311b565b6000604051808303818588803b15801561256457600080fd5b505af1158015612578573d6000803e3d6000fd5b505050505050505050565b60408051608081018252600080825260208201819052918101829052606081019190915260a086015160808701516040516317a8f53760e31b8152600481018890526001600160a01b03808316916396834ad39185169063bd47a9b89060240160206040518083038186803b1580156125fb57600080fd5b505afa15801561260f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126339190612b75565b6040518263ffffffff1660e01b815260040161265191815260200190565b60806040518083038186803b15801561266957600080fd5b505afa15801561267d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126a19190612cfe565b925042866001600160401b031684606001516126bd9190613508565b1180156126d157506000836000015160070b135b61270b5760405162461bcd60e51b815260206004820152600b60248201526a5374616c6520707269636560a81b60448201526064016105a0565b6000670de0b6b3a76400006127208682613508565b61272a9088613540565b6127349190613520565b90506000670de0b6b3a764000061274b878261355f565b6127559089613540565b61275f9190613520565b90508160070b856000015160070b1315801561278557508060070b856000015160070b12155b6127d15760405162461bcd60e51b815260206004820152601b60248201527f50797468207072696365206578636565647320736c697070616765000000000060448201526064016105a0565b5050505095945050505050565b82805482825590600052602060002090601f016020900481019282156128905791602002820160005b8382111561286157835183826101000a81548160ff0219169083600181111561284057634e487b7160e01b600052602160045260246000fd5b02179055509260200192600101602081600001049283019260010302612807565b801561288e5782816101000a81549060ff0219169055600101602081600001049283019260010302612861565b505b5061289c9291506128e2565b5090565b50805460008255600a029060005260206000209081019061075091906128f7565b50805460008255600a0290600052602060002090810190610750919061297c565b5b8082111561289c57600081556001016128e3565b8082111561289c5780546001600160a01b031916815560006001820181905560028201805467ffffffffffffffff19169055600382018190556004820181905561294460058301826129f7565b506006810180546001600160a01b03199081169091556000600783018190556008830180549092169091556009820155600a016128f7565b5b8082111561289c5780546001600160a01b031990811682556000600183018190556002830180546001600160801b031916905560038301819055600483018190556005830180546001600160a81b031916905560068301819055600783018054909216909155600882018190556009820155600a0161297d565b50805460008255601f01602090049060005260206000209081019061075091906128e2565b8051612a2781613687565b919050565b60008083601f840112612a3d578182fd5b5081356001600160401b03811115612a53578182fd5b6020830191508360208260051b8501011115612a6e57600080fd5b9250929050565b60006101008284031215612a87578081fd5b50919050565b60006101408284031215612a87578081fd5b600060208284031215612ab0578081fd5b8135612abb81613687565b9392505050565b600060208284031215612ad3578081fd5b8151612abb81613687565b60008060408385031215612af0578081fd5b8235612afb81613687565b91506020830135612b0b81613687565b809150509250929050565b60008060208385031215612b28578182fd5b82356001600160401b03811115612b3d578283fd5b612b4985828601612a2c565b90969095509350505050565b600060208284031215612b66578081fd5b81358015158114612abb578182fd5b600060208284031215612b86578081fd5b5051919050565b600060208284031215612b9e578081fd5b813560028110612abb578182fd5b600060c08284031215612bbd578081fd5b60405160c081018181106001600160401b0382111715612beb57634e487b7160e01b83526041600452602483fd5b6040528251612bf981613687565b81526020830151612c0981613687565b60208201526040830151612c1c81613687565b60408201526060830151612c2f81613687565b60608201526080830151612c4281613687565b6080820152612c5360a08401612a1c565b60a08201529392505050565b600060208284031215612c70578081fd5b81356001600160401b03811115612c85578182fd5b612c9184828501612a75565b949350505050565b600080600060408486031215612cad578081fd5b83356001600160401b0380821115612cc3578283fd5b612ccf87838801612a75565b94506020860135915080821115612ce4578283fd5b50612cf186828701612a2c565b9497909650939450505050565b600060808284031215612d0f578081fd5b604051608081018181106001600160401b0382111715612d3d57634e487b7160e01b83526041600452602483fd5b6040528251600781900b8114612d51578283fd5b81526020830151612d618161369c565b60208201526040830151600381900b8114612d7a578283fd5b60408201526060928301519281019290925250919050565b60006101408284031215612da4578081fd5b612abb8383612a8d565b60008060006101608486031215612dc3578081fd5b612dcd8585612a8d565b92506101408401356001600160401b03811115612de8578182fd5b612cf186828701612a2c565b600060208284031215612e05578081fd5b5035919050565b600060208284031215612e1d578081fd5b8135612abb8161369c565b600060208284031215612e39578081fd5b8151612abb8161369c565b6000815180845260208085019450808401835b83811015612e7a57612e6a878351612ef9565b9582019590820190600101612e57565b509495945050505050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b60008151808452815b81811015612ed357602081850181015186830182015201612eb7565b81811115612ee45782602083870101525b50601f01601f19169290920160200192915050565b60028110612f1757634e487b7160e01b600052602160045260246000fd5b9052565b80516001600160a01b031682526000610140602083015160208501526040830151612f5160408601826001600160401b03169052565b50606083015160608501526080830151608085015260a08301518160a0860152612f7d82860182612e44565b91505060c0830151612f9a60c08601826001600160a01b03169052565b5060e083015160e085015261010080840151612fc0828701826001600160a01b03169052565b5050610120928301519390920192909252919050565b80516001600160a01b0316825260208101516020830152604081015161300760408401826001600160401b03169052565b50606081015161302260608401826001600160401b03169052565b506080810151608083015260a081015160a083015260c081015161304960c0840182612ef9565b5060e081015161306460e08401826001600160a01b03169052565b506101008181015190830152610120808201516001600160a01b031690830152610140808201519083015261016090810151910152565b6001600160a01b038d81168252602082018d90526001600160401b038c811660408401528b166060830152608082018a905260a082018990526101808201906130e760c084018a612ef9565b96871660e0830152610100820195909552929094166101208301526101408201526101600191909152979650505050505050565b60208082528181018390526000906040600585901b8401810190840186845b878110156131a557868403603f190183528135368a9003601e1901811261315f578687fd5b890180356001600160401b03811115613176578788fd5b8036038b1315613184578788fd5b6131918682898501612e85565b95505050918401919084019060010161313a565b5091979650505050505050565b6040815260006131c56040830185612eae565b82810360208401526131d78185612f1b565b95945050505050565b60006101a08083526131f481840186612eae565b915050612abb6020830184612fd6565b60208082526017908201527f456d707479207072696365207570646174652064617461000000000000000000604082015260600190565b6020808252603c908201527f5468697320616374696f6e2063616e6e6f7420626520706572666f726d65642060408201527f7768696c652074686520636f6e74726163742069732070617573656400000000606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b602080825282516001600160a01b0316828201528201516040808301919091528201516001600160401b038116606083015260009050606083810151805160070b608085015260208101516001600160401b031660a0850152604081015160030b60c08501529081015160e08401525060808301516101608061010085015261335c610180850183612e44565b915060a08501516133796101208601826001600160a01b03169052565b5060c085015161014085015260e0909401516001600160a01b03169390920192909252919050565b81516001600160a01b031681526101a081016020830151602083015260408301516133d760408401826001600160401b03169052565b5060608301516133f260608401826001600160401b03169052565b5060808301516134356080840182805160070b82526001600160401b036020820151166020830152604081015160030b6040830152606081015160608301525050565b5060a083015161010061344a81850183612ef9565b60c08501519150610120613468818601846001600160a01b03169052565b60e0860151610140860152908501516001600160a01b03166101608501529093015161018090920191909152919050565b602081526000612abb6020830184612f1b565b61018081016134bb8284612fd6565b92915050565b6000808335601e198436030181126134d7578283fd5b8301803591506001600160401b038211156134f0578283fd5b6020019150600581901b3603821315612a6e57600080fd5b6000821982111561351b5761351b6135d0565b500190565b60008261353b57634e487b7160e01b81526012600452602481fd5b500490565b600081600019048311821515161561355a5761355a6135d0565b500290565b600082821015613571576135716135d0565b500390565b601f8201601f191681016001600160401b03811182821017156135a957634e487b7160e01b600052604160045260246000fd5b6040525050565b600060ff821660ff8114156135c7576135c76135d0565b60010192915050565b634e487b7160e01b600052601160045260246000fd5b600060033d11156135fb57600481823e5160e01c5b90565b600060443d101561360c5790565b6040516003193d81016004833e81513d6001600160401b03816024840111818411171561363b57505050505090565b82850191508151818111156136535750505050505090565b843d870101602082850101111561366d5750505050505090565b61367c60208286010187613576565b509095945050505050565b6001600160a01b038116811461075057600080fd5b6001600160401b038116811461075057600080fdfea2646970667358221220000f7a9fe5170ec754870fc9d7d2f69d01a230b649f5f02df885b1a51cbc387064736f6c63430008040033
Deployed Bytecode
0x6080604052600436106101665760003560e01c806353a47bb7116100d15780638d2ccac71161008a578063ad043f2d11610064578063ad043f2d14610489578063c3b83f5f1461049c578063ebc79772146104bc578063f6264e75146104d157600080fd5b80638d2ccac71461043a5780638da5cb5b1461044d57806391b4ded91461047357600080fd5b806353a47bb7146102fc5780635c975abb1461031c5780636032a02714610346578063766f924a1461036657806379ba5097146103a35780638411f183146103b857600080fd5b80631c07d3c3116101235780631c07d3c314610231578063214e72cb146102695780632a789dc41461027c5780632e8eedd5146102915780633ab76e9f146102a4578063485cc955146102dc57600080fd5b80630652b57a1461016b57806313af40351461018d5780631627540c146101ad57806316c38b3c146101cd57806319297361146101ed5780631936f21c14610211575b600080fd5b34801561017757600080fd5b5061018b610186366004612a9f565b6104f1565b005b34801561019957600080fd5b5061018b6101a8366004612a9f565b61054e565b3480156101b957600080fd5b5061018b6101c8366004612a9f565b610687565b3480156101d957600080fd5b5061018b6101e8366004612b55565b6106dd565b3480156101f957600080fd5b506006545b6040519081526020015b60405180910390f35b34801561021d57600080fd5b5061018b61022c366004612c5f565b610753565b34801561023d57600080fd5b5061025161024c366004612df4565b610a7f565b6040516102089c9b9a9998979695949392919061309b565b61018b610277366004612b16565b610b0d565b34801561028857600080fd5b506007546101fe565b61018b61029f366004612dae565b61113a565b3480156102b057600080fd5b506008546102c4906001600160a01b031681565b6040516001600160a01b039091168152602001610208565b3480156102e857600080fd5b5061018b6102f7366004612ade565b611430565b34801561030857600080fd5b506001546102c4906001600160a01b031681565b34801561032857600080fd5b506003546103369060ff1681565b6040519015158152602001610208565b34801561035257600080fd5b5061018b610361366004612d92565b61150e565b34801561037257600080fd5b5060055461038b9061010090046001600160401b031681565b6040516001600160401b039091168152602001610208565b3480156103af57600080fd5b5061018b611875565b3480156103c457600080fd5b506103d86103d3366004612df4565b611972565b604080516001600160a01b039a8b16815260208101999099526001600160401b039097169688019690965260608701949094526080860192909252851660a085015260c08401529290921660e082015261010081019190915261012001610208565b61018b610448366004612c99565b6119e8565b34801561045957600080fd5b506000546102c4906201000090046001600160a01b031681565b34801561047f57600080fd5b506101fe60025481565b61018b610497366004612b16565b611d08565b3480156104a857600080fd5b5061018b6104b7366004612a9f565b612254565b3480156104c857600080fd5b5061018b61236d565b3480156104dd57600080fd5b5061018b6104ec366004612e0c565b6123cb565b6104f961242a565b600880546001600160a01b0319166001600160a01b0383169081179091556040519081527f954328d28753080b3c499697bde218fd8b53e924669801835383aa346e6940ee906020015b60405180910390a150565b6001600160a01b0381166105a95760405162461bcd60e51b815260206004820152601960248201527f4f776e657220616464726573732063616e6e6f7420626520300000000000000060448201526064015b60405180910390fd5b600154600160a01b900460ff16156106155760405162461bcd60e51b815260206004820152602960248201527f416c726561647920696e697469616c697a65642c20757365206e6f6d696e617460448201526832a732bba7bbb732b960b91b60648201526084016105a0565b6001805460ff60a01b1916600160a01b179055600080546001600160a01b03831662010000810262010000600160b01b03199092169190911782556040805192835260208301919091527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9101610543565b61068f61242a565b600180546001600160a01b0319166001600160a01b0383169081179091556040519081527f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce2290602001610543565b6106e561242a565b60035460ff16151581151514156106f95750565b6003805460ff191682151590811790915560ff161561071757426002555b60035460405160ff909116151581527f8fb6c181ee25a520cf3dd6565006ef91229fcfe5a989566c2a3b8c115570cec590602001610543565b50565b6001600460008282546107669190613508565b909155505060045460035460ff16156107915760405162461bcd60e51b81526004016105a09061323b565b6000604051806101400160405280336001600160a01b03168152602001846000013581526020018460200160208101906107cb9190612e0c565b6001600160401b0316815260200184604001358152602001846060013581526020018480608001906107fd91906134c1565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525050509082525060200161084460c0860160a08701612a9f565b6001600160a01b0316815260c0850135602082015260400161086d610100860160e08701612a9f565b6001600160a01b039081168252426020928301526007805460018101825560009190915283517fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c688600a90920291820180546001600160a01b03191691909316178255838301517fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68982015560408401517fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68a8201805467ffffffffffffffff19166001600160401b0390921691909117905560608401517fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68b82015560808401517fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68c82015560a08401518051949550859492936109ce937fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68d909301929101906127de565b5060c08201516006820180546001600160a01b039283166001600160a01b03199182161790915560e08401516007840155610100840151600884018054919093169116179055610120909101516009909101556040517f099eb78f69f1559bb54045718ce32bd1bcca14c366705ae70449b9ccf154623690610a51908390613499565b60405180910390a1506004548114610a7b5760405162461bcd60e51b81526004016105a090613298565b5050565b60068181548110610a8f57600080fd5b60009182526020909120600a909102018054600182015460028301546003840154600485015460058601546006870154600788015460088901546009909901546001600160a01b039889169a5096986001600160401b0380881699600160401b90980416979596949560ff851695610100909504851694909216918c565b600160046000828254610b209190613508565b909155505060045460035460ff1615610b4b5760405162461bcd60e51b81526004016105a09061323b565b600754610b8f5760405162461bcd60e51b81526020600482015260126024820152714e6f2070656e64696e67206d61726b65747360701b60448201526064016105a0565b81610bac5760405162461bcd60e51b81526004016105a090613204565b600854604080516351cfd60960e11b815290516000926001600160a01b03169163a39fac129160048083019260c0929190829003018186803b158015610bf157600080fd5b505afa158015610c05573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c299190612bac565b9050610c3a816080015185856124a4565b60008160a0015190506000816001600160a01b031663a201b3076040518163ffffffff1660e01b815260040160206040518083038186803b158015610c7e57600080fd5b505afa158015610c92573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cb69190612e28565b90506000805b60075460ff821610156110c357600060078260ff1681548110610cef57634e487b7160e01b600052603260045260246000fd5b60009182526020918290206040805161014081018252600a90930290910180546001600160a01b0316835260018101548385015260028101546001600160401b03168383015260038101546060840152600481015460808401526005810180548351818702810187019094528084529394919360a086019392830182828015610dd557602002820191906000526020600020906000905b82829054906101000a900460ff166001811115610db357634e487b7160e01b600052602160045260246000fd5b815260206001928301818104948501949093039092029101808411610d865790505b505050918352505060068201546001600160a01b0390811660208301526007830154604083015260088301541660608201526009909101546080909101526005546101208201519192504291610e399161010090046001600160401b031690613508565b11610e4457506110b1565b6000610e5f8783602001518785606001518660800151612583565b60085460405163bf40fac160e01b8152602060048201526016602482015275436861696e656453706565644d61726b657473414d4d60501b60448201529192506001600160a01b03169063bf40fac19060640160206040518083038186803b158015610eca57600080fd5b505afa158015610ede573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f029190612ac2565b6001600160a01b0316630bfd50ce60405180610100016040528085600001516001600160a01b031681526020018560200151815260200185604001516001600160401b031681526020018481526020018560a0015181526020018560c001516001600160a01b031681526020018560e0015181526020018561010001516001600160a01b03168152506040518263ffffffff1660e01b8152600401610fa791906132cf565b600060405180830381600087803b158015610fc157600080fd5b505af1925050508015610fd2575060015b6110a057610fde6135e6565b806308c379a0141561103d5750610ff36135fe565b80610ffe575061103f565b7fe84e33c8088d8797d0968617fc974690124648a9fe6f643c976dbaa434e86c4e818460405161102f9291906131b2565b60405180910390a1506110ae565b505b3d808015611069576040519150601f19603f3d011682016040523d82523d6000602084013e61106e565b606091505b507fea71beab728aa700f4b1b124c203ca9981b99696ed9f56b3def56a1b3a138332818460405161102f9291906131b2565b836110aa816135b0565b9450505b50505b806110bb816135b0565b915050610cbc565b5060078054906110d49060006128a0565b6040805182815260ff841660208201527f48be52c64e0a5ff7b386f592283a0ee5b473efc8a04c47cca0e942d90574d376910160405180910390a1505050505060045481146111355760405162461bcd60e51b81526004016105a090613298565b505050565b60016004600082825461114d9190613508565b909155505060045460035460ff16156111785760405162461bcd60e51b81526004016105a09061323b565b816111955760405162461bcd60e51b81526004016105a090613204565b600854604080516351cfd60960e11b815290516000926001600160a01b03169163a39fac129160048083019260c0929190829003018186803b1580156111da57600080fd5b505afa1580156111ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112129190612bac565b9050611223816080015185856124a4565b60008160a00151905060006112b7838860000135846001600160a01b031663a201b3076040518163ffffffff1660e01b815260040160206040518083038186803b15801561127057600080fd5b505afa158015611284573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112a89190612e28565b8a606001358b60800135612583565b9050816001600160a01b031663e0223eea604051806101400160405280336001600160a01b031681526020018a6000013581526020018a60200160208101906113009190612e0c565b6001600160401b0316815260200161131e60608c0160408d01612e0c565b6001600160401b031681526020810185905260400161134360c08c0160a08d01612b8d565b600181111561136257634e487b7160e01b600052602160045260246000fd5b815260200161137760e08c0160c08d01612a9f565b6001600160a01b0316815260e08b013560208201526040016113a16101208c016101008d01612a9f565b6001600160a01b031681526020018a61012001358152506040518263ffffffff1660e01b81526004016113d491906133a1565b600060405180830381600087803b1580156113ee57600080fd5b505af1158015611402573d6000803e3d6000fd5b50505050505050600454811461142a5760405162461bcd60e51b81526004016105a090613298565b50505050565b600054610100900460ff1661144b5760005460ff161561144f565b303b155b6114b25760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016105a0565b600054610100900460ff161580156114d4576000805461ffff19166101011790555b6114dd8361054e565b600880546001600160a01b0319166001600160a01b0384161790558015611135576000805461ff0019169055505050565b6001600460008282546115219190613508565b909155505060045460035460ff161561154c5760405162461bcd60e51b81526004016105a09061323b565b6000604051806101800160405280336001600160a01b03168152602001846000013581526020018460200160208101906115869190612e0c565b6001600160401b031681526020016115a46060860160408701612e0c565b6001600160401b03168152606080860135602083015260808601356040830152016115d560c0860160a08701612b8d565b60018111156115f457634e487b7160e01b600052602160045260246000fd5b815260200161160960e0860160c08701612a9f565b6001600160a01b0316815260e0850135602082015260400161163361012086016101008701612a9f565b6001600160a01b0390811682526101208601356020808401919091524260409384015260068054600181810183556000929092528551600a9091027ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f81018054929095166001600160a01b0319909216919091178455918501517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d40830155928401517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d418201805460608701516001600160401b03908116600160401b026001600160801b031990921693169290921791909117905560808401517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d4282015560a08401517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d4382015560c08401517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d449091018054949550859492939192909160ff199091169083818111156117d657634e487b7160e01b600052602160045260246000fd5b021790555060e0820151600582018054610100600160a81b0319166101006001600160a01b0393841681029190911790915583015160068301556101208301516007830180546001600160a01b031916919092161790556101408201516008820155610160909101516009909101556040517faa9b85a2e5b93e844f4da51afaa437f075601edf0a59b74db14929d59e2d797790610a519083906134ac565b6001546001600160a01b031633146118ed5760405162461bcd60e51b815260206004820152603560248201527f596f75206d757374206265206e6f6d696e61746564206265666f726520796f7560448201527402063616e20616363657074206f776e65727368697605c1b60648201526084016105a0565b60005460015460408051620100009093046001600160a01b03908116845290911660208301527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c910160405180910390a1600180546000805462010000600160b01b0319166001600160a01b03831662010000021790556001600160a01b0319169055565b6007818154811061198257600080fd5b60009182526020909120600a90910201805460018201546002830154600384015460048501546006860154600787015460088801546009909801546001600160a01b03978816995095976001600160401b03909516969395929491841693909291169089565b6001600460008282546119fb9190613508565b909155505060045460035460ff1615611a265760405162461bcd60e51b81526004016105a09061323b565b81611a435760405162461bcd60e51b81526004016105a090613204565b600854604080516351cfd60960e11b815290516000926001600160a01b03169163a39fac129160048083019260c0929190829003018186803b158015611a8857600080fd5b505afa158015611a9c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ac09190612bac565b9050611ad1816080015185856124a4565b60008160a0015190506000611b65838860000135846001600160a01b031663a201b3076040518163ffffffff1660e01b815260040160206040518083038186803b158015611b1e57600080fd5b505afa158015611b32573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b569190612e28565b8a604001358b60600135612583565b60085460405163bf40fac160e01b8152602060048201526016602482015275436861696e656453706565644d61726b657473414d4d60501b60448201529192506001600160a01b03169063bf40fac19060640160206040518083038186803b158015611bd057600080fd5b505afa158015611be4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c089190612ac2565b6001600160a01b0316630bfd50ce604051806101000160405280336001600160a01b031681526020018a6000013581526020018a6020016020810190611c4e9190612e0c565b6001600160401b0316815260208101859052604001611c7060808c018c6134c1565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602001611cb760c08c0160a08d01612a9f565b6001600160a01b0316815260c08b01356020820152604001611ce06101008c0160e08d01612a9f565b6001600160a01b03168152506040518263ffffffff1660e01b81526004016113d491906132cf565b600160046000828254611d1b9190613508565b909155505060045460035460ff1615611d465760405162461bcd60e51b81526004016105a09061323b565b600654611d8a5760405162461bcd60e51b81526020600482015260126024820152714e6f2070656e64696e67206d61726b65747360701b60448201526064016105a0565b81611da75760405162461bcd60e51b81526004016105a090613204565b600854604080516351cfd60960e11b815290516000926001600160a01b03169163a39fac129160048083019260c0929190829003018186803b158015611dec57600080fd5b505afa158015611e00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e249190612bac565b9050611e35816080015185856124a4565b60008160a0015190506000816001600160a01b031663a201b3076040518163ffffffff1660e01b815260040160206040518083038186803b158015611e7957600080fd5b505afa158015611e8d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611eb19190612e28565b90506000805b60065460ff8216101561224357600060068260ff1681548110611eea57634e487b7160e01b600052603260045260246000fd5b60009182526020918290206040805161018081018252600a90930290910180546001600160a01b031683526001808201549484019490945260028101546001600160401b0380821693850193909352600160401b9004909116606083015260038101546080830152600481015460a083015260058101549192909160c084019160ff90911690811115611f8d57634e487b7160e01b600052602160045260246000fd5b6001811115611fac57634e487b7160e01b600052602160045260246000fd5b8152600582810154610100908190046001600160a01b0390811660208501526006850154604085015260078501541660608401526008840154608084015260099093015460a09092019190915254610160830151929350429261201b929091046001600160401b031690613508565b116120265750612231565b60006120418783602001518785608001518660a00151612583565b9050856001600160a01b031663e0223eea60405180610140016040528085600001516001600160a01b031681526020018560200151815260200185604001516001600160401b0316815260200185606001516001600160401b031681526020018481526020018560c0015160018111156120cb57634e487b7160e01b600052602160045260246000fd5b81526020018560e001516001600160a01b0316815260200185610100015181526020018561012001516001600160a01b031681526020018561014001518152506040518263ffffffff1660e01b815260040161212791906133a1565b600060405180830381600087803b15801561214157600080fd5b505af1925050508015612152575060015b6122205761215e6135e6565b806308c379a014156121bd57506121736135fe565b8061217e57506121bf565b7f07f812267f276d6fcc4b3a3d1f2797c3455cdc13d47462b1567a849842e13c4681846040516121af9291906131e0565b60405180910390a15061222e565b505b3d8080156121e9576040519150601f19603f3d011682016040523d82523d6000602084013e6121ee565b606091505b507faf05d7cd9581ee93ea4340706c133f4b6b0bc1f1a71b7fbcdd2dccc025e6d5bd81846040516121af9291906131e0565b8361222a816135b0565b9450505b50505b8061223b816135b0565b915050611eb7565b5060068054906110d49060006128c1565b61225c61242a565b6001600160a01b0381166122a45760405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b60448201526064016105a0565b600154600160a81b900460ff16156122f45760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481d1c985b9cd9995c9c9959606a1b60448201526064016105a0565b600080546001600160a01b038381166201000081810262010000600160b01b031990941693909317938490556001805460ff60a81b1916600160a81b1790556040805193909404909116825260208201527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9101610543565b60055460ff16156123b65760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b60448201526064016105a0565b6005805460ff19166001908117909155600455565b6123d361242a565b6005805468ffffffffffffffff0019166101006001600160401b038416908102919091179091556040519081527f41b95b0cd63e823b0fff2701a35e7ab970829374fa79149ca1b1d1dce73e001890602001610543565b6000546201000090046001600160a01b031633146124a25760405162461bcd60e51b815260206004820152602f60248201527f4f6e6c792074686520636f6e7472616374206f776e6572206d6179207065726660448201526e37b936903a3434b99030b1ba34b7b760891b60648201526084016105a0565b565b60405163d47eed4560e01b815283906001600160a01b0382169063ef9e5e2890829063d47eed45906124dc908890889060040161311b565b60206040518083038186803b1580156124f457600080fd5b505afa158015612508573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061252c9190612b75565b85856040518463ffffffff1660e01b815260040161254b92919061311b565b6000604051808303818588803b15801561256457600080fd5b505af1158015612578573d6000803e3d6000fd5b505050505050505050565b60408051608081018252600080825260208201819052918101829052606081019190915260a086015160808701516040516317a8f53760e31b8152600481018890526001600160a01b03808316916396834ad39185169063bd47a9b89060240160206040518083038186803b1580156125fb57600080fd5b505afa15801561260f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126339190612b75565b6040518263ffffffff1660e01b815260040161265191815260200190565b60806040518083038186803b15801561266957600080fd5b505afa15801561267d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126a19190612cfe565b925042866001600160401b031684606001516126bd9190613508565b1180156126d157506000836000015160070b135b61270b5760405162461bcd60e51b815260206004820152600b60248201526a5374616c6520707269636560a81b60448201526064016105a0565b6000670de0b6b3a76400006127208682613508565b61272a9088613540565b6127349190613520565b90506000670de0b6b3a764000061274b878261355f565b6127559089613540565b61275f9190613520565b90508160070b856000015160070b1315801561278557508060070b856000015160070b12155b6127d15760405162461bcd60e51b815260206004820152601b60248201527f50797468207072696365206578636565647320736c697070616765000000000060448201526064016105a0565b5050505095945050505050565b82805482825590600052602060002090601f016020900481019282156128905791602002820160005b8382111561286157835183826101000a81548160ff0219169083600181111561284057634e487b7160e01b600052602160045260246000fd5b02179055509260200192600101602081600001049283019260010302612807565b801561288e5782816101000a81549060ff0219169055600101602081600001049283019260010302612861565b505b5061289c9291506128e2565b5090565b50805460008255600a029060005260206000209081019061075091906128f7565b50805460008255600a0290600052602060002090810190610750919061297c565b5b8082111561289c57600081556001016128e3565b8082111561289c5780546001600160a01b031916815560006001820181905560028201805467ffffffffffffffff19169055600382018190556004820181905561294460058301826129f7565b506006810180546001600160a01b03199081169091556000600783018190556008830180549092169091556009820155600a016128f7565b5b8082111561289c5780546001600160a01b031990811682556000600183018190556002830180546001600160801b031916905560038301819055600483018190556005830180546001600160a81b031916905560068301819055600783018054909216909155600882018190556009820155600a0161297d565b50805460008255601f01602090049060005260206000209081019061075091906128e2565b8051612a2781613687565b919050565b60008083601f840112612a3d578182fd5b5081356001600160401b03811115612a53578182fd5b6020830191508360208260051b8501011115612a6e57600080fd5b9250929050565b60006101008284031215612a87578081fd5b50919050565b60006101408284031215612a87578081fd5b600060208284031215612ab0578081fd5b8135612abb81613687565b9392505050565b600060208284031215612ad3578081fd5b8151612abb81613687565b60008060408385031215612af0578081fd5b8235612afb81613687565b91506020830135612b0b81613687565b809150509250929050565b60008060208385031215612b28578182fd5b82356001600160401b03811115612b3d578283fd5b612b4985828601612a2c565b90969095509350505050565b600060208284031215612b66578081fd5b81358015158114612abb578182fd5b600060208284031215612b86578081fd5b5051919050565b600060208284031215612b9e578081fd5b813560028110612abb578182fd5b600060c08284031215612bbd578081fd5b60405160c081018181106001600160401b0382111715612beb57634e487b7160e01b83526041600452602483fd5b6040528251612bf981613687565b81526020830151612c0981613687565b60208201526040830151612c1c81613687565b60408201526060830151612c2f81613687565b60608201526080830151612c4281613687565b6080820152612c5360a08401612a1c565b60a08201529392505050565b600060208284031215612c70578081fd5b81356001600160401b03811115612c85578182fd5b612c9184828501612a75565b949350505050565b600080600060408486031215612cad578081fd5b83356001600160401b0380821115612cc3578283fd5b612ccf87838801612a75565b94506020860135915080821115612ce4578283fd5b50612cf186828701612a2c565b9497909650939450505050565b600060808284031215612d0f578081fd5b604051608081018181106001600160401b0382111715612d3d57634e487b7160e01b83526041600452602483fd5b6040528251600781900b8114612d51578283fd5b81526020830151612d618161369c565b60208201526040830151600381900b8114612d7a578283fd5b60408201526060928301519281019290925250919050565b60006101408284031215612da4578081fd5b612abb8383612a8d565b60008060006101608486031215612dc3578081fd5b612dcd8585612a8d565b92506101408401356001600160401b03811115612de8578182fd5b612cf186828701612a2c565b600060208284031215612e05578081fd5b5035919050565b600060208284031215612e1d578081fd5b8135612abb8161369c565b600060208284031215612e39578081fd5b8151612abb8161369c565b6000815180845260208085019450808401835b83811015612e7a57612e6a878351612ef9565b9582019590820190600101612e57565b509495945050505050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b60008151808452815b81811015612ed357602081850181015186830182015201612eb7565b81811115612ee45782602083870101525b50601f01601f19169290920160200192915050565b60028110612f1757634e487b7160e01b600052602160045260246000fd5b9052565b80516001600160a01b031682526000610140602083015160208501526040830151612f5160408601826001600160401b03169052565b50606083015160608501526080830151608085015260a08301518160a0860152612f7d82860182612e44565b91505060c0830151612f9a60c08601826001600160a01b03169052565b5060e083015160e085015261010080840151612fc0828701826001600160a01b03169052565b5050610120928301519390920192909252919050565b80516001600160a01b0316825260208101516020830152604081015161300760408401826001600160401b03169052565b50606081015161302260608401826001600160401b03169052565b506080810151608083015260a081015160a083015260c081015161304960c0840182612ef9565b5060e081015161306460e08401826001600160a01b03169052565b506101008181015190830152610120808201516001600160a01b031690830152610140808201519083015261016090810151910152565b6001600160a01b038d81168252602082018d90526001600160401b038c811660408401528b166060830152608082018a905260a082018990526101808201906130e760c084018a612ef9565b96871660e0830152610100820195909552929094166101208301526101408201526101600191909152979650505050505050565b60208082528181018390526000906040600585901b8401810190840186845b878110156131a557868403603f190183528135368a9003601e1901811261315f578687fd5b890180356001600160401b03811115613176578788fd5b8036038b1315613184578788fd5b6131918682898501612e85565b95505050918401919084019060010161313a565b5091979650505050505050565b6040815260006131c56040830185612eae565b82810360208401526131d78185612f1b565b95945050505050565b60006101a08083526131f481840186612eae565b915050612abb6020830184612fd6565b60208082526017908201527f456d707479207072696365207570646174652064617461000000000000000000604082015260600190565b6020808252603c908201527f5468697320616374696f6e2063616e6e6f7420626520706572666f726d65642060408201527f7768696c652074686520636f6e74726163742069732070617573656400000000606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b602080825282516001600160a01b0316828201528201516040808301919091528201516001600160401b038116606083015260009050606083810151805160070b608085015260208101516001600160401b031660a0850152604081015160030b60c08501529081015160e08401525060808301516101608061010085015261335c610180850183612e44565b915060a08501516133796101208601826001600160a01b03169052565b5060c085015161014085015260e0909401516001600160a01b03169390920192909252919050565b81516001600160a01b031681526101a081016020830151602083015260408301516133d760408401826001600160401b03169052565b5060608301516133f260608401826001600160401b03169052565b5060808301516134356080840182805160070b82526001600160401b036020820151166020830152604081015160030b6040830152606081015160608301525050565b5060a083015161010061344a81850183612ef9565b60c08501519150610120613468818601846001600160a01b03169052565b60e0860151610140860152908501516001600160a01b03166101608501529093015161018090920191909152919050565b602081526000612abb6020830184612f1b565b61018081016134bb8284612fd6565b92915050565b6000808335601e198436030181126134d7578283fd5b8301803591506001600160401b038211156134f0578283fd5b6020019150600581901b3603821315612a6e57600080fd5b6000821982111561351b5761351b6135d0565b500190565b60008261353b57634e487b7160e01b81526012600452602481fd5b500490565b600081600019048311821515161561355a5761355a6135d0565b500290565b600082821015613571576135716135d0565b500390565b601f8201601f191681016001600160401b03811182821017156135a957634e487b7160e01b600052604160045260246000fd5b6040525050565b600060ff821660ff8114156135c7576135c76135d0565b60010192915050565b634e487b7160e01b600052601160045260246000fd5b600060033d11156135fb57600481823e5160e01c5b90565b600060443d101561360c5790565b6040516003193d81016004833e81513d6001600160401b03816024840111818411171561363b57505050505090565b82850191508151818111156136535750505050505090565b843d870101602082850101111561366d5750505050505090565b61367c60208286010187613576565b509095945050505050565b6001600160a01b038116811461075057600080fd5b6001600160401b038116811461075057600080fdfea2646970667358221220000f7a9fe5170ec754870fc9d7d2f69d01a230b649f5f02df885b1a51cbc387064736f6c63430008040033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
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.