Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Contract Name:
PositionalMarketData
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; // Inheritance import "./Position.sol"; import "./PositionalMarket.sol"; import "./PositionalMarketManager.sol"; import "../RangedMarkets/RangedMarket.sol"; import "../RangedMarkets/RangedMarketsAMM.sol"; import "../interfaces/IThalesAMM.sol"; import "../utils/proxy/solidity-0.8.0/ProxyOwned.sol"; import "../utils/proxy/solidity-0.8.0/ProxyPausable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; contract PositionalMarketData is Initializable, ProxyOwned, ProxyPausable { struct OptionValues { uint up; uint down; } struct Deposits { uint deposited; } struct Resolution { bool resolved; bool canResolve; } struct OraclePriceAndTimestamp { uint price; uint updatedAt; } // used for things that don't change over the lifetime of the contract struct MarketParameters { address creator; PositionalMarket.Options options; PositionalMarket.Times times; PositionalMarket.OracleDetails oracleDetails; PositionalMarketManager.Fees fees; } struct MarketData { OraclePriceAndTimestamp oraclePriceAndTimestamp; Deposits deposits; Resolution resolution; PositionalMarket.Phase phase; PositionalMarket.Side result; OptionValues totalSupplies; } struct AccountData { OptionValues balances; } struct ActiveMarketsPriceImpact { address market; int upPriceImpact; int downPriceImpact; } struct ActiveMarketsLiquidity { address market; uint upLiquidity; uint downLiquidity; } struct ActiveMarketsPrices { address market; uint upPrice; uint downPrice; } struct ActiveMarketsInfoPerPosition { address market; uint price; uint liquidity; int priceImpact; uint strikePrice; } struct RangedMarketsInfoPerPosition { address market; uint price; uint liquidity; int priceImpact; uint leftPrice; uint rightPrice; } struct AmmMarketData { uint upBuyLiquidity; uint downBuyLiquidity; uint upSellLiquidity; uint downSellLiquidity; uint upBuyPrice; uint downBuyPrice; uint upSellPrice; uint downSellPrice; int upBuyPriceImpact; int downBuyPriceImpact; int upSellPriceImpact; int downSellPriceImpact; uint iv; bool isMarketInAMMTrading; } struct RangedAmmMarketData { uint inBuyLiquidity; uint outBuyLiquidity; uint inSellLiquidity; uint outSellLiquidity; uint inBuyPrice; uint outBuyPrice; uint inSellPrice; uint outSellPrice; int inPriceImpact; int outPriceImpact; } uint private constant ONE = 1e18; address public manager; address public thalesAMM; address public rangedMarketsAMM; function initialize(address _owner) external initializer { setOwner(_owner); } /// @notice getMarketParameters returns market details /// @param market PositionalMarket /// @return MarketParameters function getMarketParameters(PositionalMarket market) external view returns (MarketParameters memory) { (Position up, Position down) = market.options(); (uint maturityDate, uint expiryDate) = market.times(); (bytes32 key, uint strikePrice, uint finalPrice, bool customMarket, address iOracleInstanceAddress) = market .oracleDetails(); (uint poolFee, uint creatorFee) = market.fees(); MarketParameters memory data = MarketParameters( market.creator(), PositionalMarket.Options(up, down), PositionalMarket.Times(maturityDate, expiryDate), PositionalMarket.OracleDetails(key, strikePrice, finalPrice, customMarket, iOracleInstanceAddress), PositionalMarketManager.Fees(poolFee, creatorFee) ); return data; } /// @notice getMarketData returns market details /// @param market PositionalMarket /// @return MarketData function getMarketData(PositionalMarket market) external view returns (MarketData memory) { (uint price, uint updatedAt) = market.oraclePriceAndTimestamp(); (uint upSupply, uint downSupply) = market.totalSupplies(); return MarketData( OraclePriceAndTimestamp(price, updatedAt), Deposits(market.deposited()), Resolution(market.resolved(), market.canResolve()), market.phase(), market.result(), OptionValues(upSupply, downSupply) ); } /// @notice getAccountMarketData returns account balances /// @param market PositionalMarket /// @param account address of an account /// @return AccountData function getAccountMarketData(PositionalMarket market, address account) external view returns (AccountData memory) { (uint upBalance, uint downBalance) = market.balancesOf(account); return AccountData(OptionValues(upBalance, downBalance)); } /// @notice getPriceImpactForAllActiveMarkets returns price impact for all active markets /// @param start startIndex /// @param end endIndex /// @return ActiveMarketsPriceImpact function getBatchPriceImpactForAllActiveMarkets(uint start, uint end) external view returns (ActiveMarketsPriceImpact[] memory) { address[] memory activeMarkets = PositionalMarketManager(manager).activeMarkets( 0, PositionalMarketManager(manager).numActiveMarkets() ); uint endIndex = end > PositionalMarketManager(manager).numActiveMarkets() ? PositionalMarketManager(manager).numActiveMarkets() : end; ActiveMarketsPriceImpact[] memory marketPriceImpact = new ActiveMarketsPriceImpact[](endIndex - start); for (uint i = start; i < endIndex; i++) { marketPriceImpact[i - start].market = activeMarkets[i]; if (IThalesAMM(thalesAMM).isMarketInAMMTrading(activeMarkets[i])) { marketPriceImpact[i - start].upPriceImpact = IThalesAMM(thalesAMM).buyPriceImpact( activeMarkets[i], IThalesAMM.Position.Up, ONE ); marketPriceImpact[i - start].downPriceImpact = IThalesAMM(thalesAMM).buyPriceImpact( activeMarkets[i], IThalesAMM.Position.Down, ONE ); } } return marketPriceImpact; } /// @notice getBatchBasePricesForAllActiveMarkets returns base prices for all active markets /// @param start startIndex /// @param end endIndex /// @return ActiveMarketsPrices function getBatchBasePricesForAllActiveMarkets(uint start, uint end) external view returns (ActiveMarketsPrices[] memory) { address[] memory activeMarkets = PositionalMarketManager(manager).activeMarkets( 0, PositionalMarketManager(manager).numActiveMarkets() ); uint endIndex = end > PositionalMarketManager(manager).numActiveMarkets() ? PositionalMarketManager(manager).numActiveMarkets() : end; ActiveMarketsPrices[] memory marketPrices = new ActiveMarketsPrices[](endIndex - start); for (uint i = start; i < endIndex; i++) { marketPrices[i - start].market = activeMarkets[i]; if (IThalesAMM(thalesAMM).isMarketInAMMTrading(activeMarkets[i])) { marketPrices[i - start].upPrice = IThalesAMM(thalesAMM).price(activeMarkets[i], IThalesAMM.Position.Up); marketPrices[i - start].downPrice = IThalesAMM(thalesAMM).price(activeMarkets[i], IThalesAMM.Position.Down); } } return marketPrices; } /// @notice getAvailableAssets all assets currently available /// @return all available assets function getAvailableAssets() external view returns (bytes32[] memory) { address[] memory activeMarkets = PositionalMarketManager(manager).activeMarkets( 0, PositionalMarketManager(manager).numActiveMarkets() ); bytes32[] memory allActiveAssets = new bytes32[](activeMarkets.length); for (uint i = 0; i < activeMarkets.length; i++) { IPositionalMarket market = IPositionalMarket(activeMarkets[i]); (bytes32 key, , ) = market.getOracleDetails(); allActiveAssets[i] = key; } return allActiveAssets; } /// @notice getMaturityDates all strike dates currently available /// @param asset to get markets for /// @return all available dates per asset function getMaturityDates(bytes32 asset) external view returns (uint[] memory) { address[] memory activeMarkets = PositionalMarketManager(manager).activeMarkets( 0, PositionalMarketManager(manager).numActiveMarkets() ); uint[] memory activeDates = new uint[](activeMarkets.length); for (uint i = 0; i < activeMarkets.length; i++) { IPositionalMarket market = IPositionalMarket(activeMarkets[i]); (bytes32 key, , ) = market.getOracleDetails(); if (key == asset) { (uint strikeDate, ) = market.times(); activeDates[i] = strikeDate; } } return activeDates; } /// @notice get a list of all markets per asset and strike date /// @param asset to get markets for /// @param strikeDateParam asset to get markets for /// @return a list of all markets per asset and strike date function getMarketsForAssetAndStrikeDate(bytes32 asset, uint strikeDateParam) external view returns (address[] memory) { address[] memory activeMarkets = PositionalMarketManager(manager).activeMarkets( 0, PositionalMarketManager(manager).numActiveMarkets() ); address[] memory activeMarketsToReturn = new address[](activeMarkets.length); for (uint i = 0; i < activeMarkets.length; i++) { IPositionalMarket market = IPositionalMarket(activeMarkets[i]); (bytes32 key, , ) = market.getOracleDetails(); if (key == asset) { (uint strikeDate, ) = market.times(); if (strikeDate == strikeDateParam) { activeMarketsToReturn[i] = activeMarkets[i]; } } } return activeMarketsToReturn; } /// @notice market info for a list of markets and position /// @param markets to get info for /// @param position asset to get info for /// @return market info for a list of markets and position function getActiveMarketsInfoPerPosition(address[] calldata markets, IThalesAMM.Position position) external view returns (ActiveMarketsInfoPerPosition[] memory) { ActiveMarketsInfoPerPosition[] memory activeMarkets = new ActiveMarketsInfoPerPosition[](markets.length); for (uint i = 0; i < markets.length; i++) { activeMarkets[i].market = markets[i]; IPositionalMarket market = IPositionalMarket(markets[i]); (, uint strikePrice, ) = market.getOracleDetails(); activeMarkets[i].strikePrice = strikePrice; activeMarkets[i].liquidity = IThalesAMM(thalesAMM).availableToBuyFromAMM(markets[i], position); activeMarkets[i].priceImpact = IThalesAMM(thalesAMM).buyPriceImpact(markets[i], position, ONE); activeMarkets[i].price = IThalesAMM(thalesAMM).buyFromAmmQuote(markets[i], position, ONE); } return activeMarkets; } /// @notice getMaturityDates all strike dates currently available /// @param markets to get info for /// @param position asset to get info for /// @return all available dates per asset function getRangedActiveMarketsInfoPerPosition(address[] calldata markets, RangedMarket.Position position) external view returns (RangedMarketsInfoPerPosition[] memory) { RangedMarketsInfoPerPosition[] memory activeMarkets = new RangedMarketsInfoPerPosition[](markets.length); RangedMarketsAMM rangedAMMContract = RangedMarketsAMM(rangedMarketsAMM); for (uint i = 0; i < markets.length; i++) { activeMarkets[i].market = markets[i]; IPositionalMarket leftMarket = IPositionalMarket(RangedMarket(markets[i]).leftMarket()); IPositionalMarket rightMarket = IPositionalMarket(RangedMarket(markets[i]).rightMarket()); (, uint leftStrikePrice, ) = leftMarket.getOracleDetails(); (, uint rightStrikePrice, ) = rightMarket.getOracleDetails(); activeMarkets[i].leftPrice = leftStrikePrice; activeMarkets[i].rightPrice = rightStrikePrice; activeMarkets[i].liquidity = rangedAMMContract.availableToBuyFromAMM(RangedMarket(markets[i]), position); activeMarkets[i].price = rangedAMMContract.buyFromAmmQuote(RangedMarket(markets[i]), position, ONE); activeMarkets[i].priceImpact = rangedAMMContract.getPriceImpact(RangedMarket(markets[i]), position); } return activeMarkets; } /// @notice getAmmMarketData returns AMM market data /// @param market market address /// @return AmmMarketData function getAmmMarketData(address market) external view returns (AmmMarketData memory) { (bytes32 key, , ) = IPositionalMarket(market).getOracleDetails(); return AmmMarketData( IThalesAMM(thalesAMM).availableToBuyFromAMM(market, IThalesAMM.Position.Up), IThalesAMM(thalesAMM).availableToBuyFromAMM(market, IThalesAMM.Position.Down), IThalesAMM(thalesAMM).availableToSellToAMM(market, IThalesAMM.Position.Up), IThalesAMM(thalesAMM).availableToSellToAMM(market, IThalesAMM.Position.Down), IThalesAMM(thalesAMM).buyFromAmmQuote(market, IThalesAMM.Position.Up, ONE), IThalesAMM(thalesAMM).buyFromAmmQuote(market, IThalesAMM.Position.Down, ONE), IThalesAMM(thalesAMM).sellToAmmQuote(market, IThalesAMM.Position.Up, ONE), IThalesAMM(thalesAMM).sellToAmmQuote(market, IThalesAMM.Position.Down, ONE), IThalesAMM(thalesAMM).buyPriceImpact(market, IThalesAMM.Position.Up, ONE), IThalesAMM(thalesAMM).buyPriceImpact(market, IThalesAMM.Position.Down, ONE), IThalesAMM(thalesAMM).sellPriceImpact(market, IThalesAMM.Position.Up, ONE), IThalesAMM(thalesAMM).sellPriceImpact(market, IThalesAMM.Position.Down, ONE), IThalesAMM(thalesAMM).impliedVolatilityPerAsset(key), IThalesAMM(thalesAMM).isMarketInAMMTrading(market) ); } /// @notice RangedAmmMarketData returns Ranged AMM market data /// @param market ranged market /// @return RangedAmmMarketData function getRangedAmmMarketData(RangedMarket market) external view returns (RangedAmmMarketData memory) { return RangedAmmMarketData( RangedMarketsAMM(rangedMarketsAMM).availableToBuyFromAMM(market, RangedMarket.Position.In), RangedMarketsAMM(rangedMarketsAMM).availableToBuyFromAMM(market, RangedMarket.Position.Out), RangedMarketsAMM(rangedMarketsAMM).availableToSellToAMM(market, RangedMarket.Position.In), RangedMarketsAMM(rangedMarketsAMM).availableToSellToAMM(market, RangedMarket.Position.Out), RangedMarketsAMM(rangedMarketsAMM).buyFromAmmQuote(market, RangedMarket.Position.In, ONE), RangedMarketsAMM(rangedMarketsAMM).buyFromAmmQuote(market, RangedMarket.Position.Out, ONE), RangedMarketsAMM(rangedMarketsAMM).sellToAmmQuote(market, RangedMarket.Position.In, ONE), RangedMarketsAMM(rangedMarketsAMM).sellToAmmQuote(market, RangedMarket.Position.Out, ONE), RangedMarketsAMM(rangedMarketsAMM).getPriceImpact(market, RangedMarket.Position.In), RangedMarketsAMM(rangedMarketsAMM).getPriceImpact(market, RangedMarket.Position.Out) ); } function setPositionalMarketManager(address _manager) external onlyOwner { manager = _manager; emit PositionalMarketManagerChanged(_manager); } function setThalesAMM(address _thalesAMM) external onlyOwner { thalesAMM = _thalesAMM; emit SetThalesAMM(_thalesAMM); } function setRangedMarketsAMM(address _rangedMarketsAMM) external onlyOwner { rangedMarketsAMM = _rangedMarketsAMM; emit SetRangedMarketsAMM(_rangedMarketsAMM); } event PositionalMarketManagerChanged(address _manager); event SetThalesAMM(address _thalesAMM); event SetRangedMarketsAMM(address _rangedMarketsAMM); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // Inheritance import "@openzeppelin/contracts-4.4.1/token/ERC20/IERC20.sol"; import "../interfaces/IPosition.sol"; // Libraries import "@openzeppelin/contracts-4.4.1/utils/math/SafeMath.sol"; // Internal references import "./PositionalMarket.sol"; contract Position is IERC20, IPosition { using SafeMath for uint; string public name; string public symbol; uint8 public constant decimals = 18; PositionalMarket public market; mapping(address => uint) public override balanceOf; uint public override totalSupply; // The argument order is allowance[owner][spender] mapping(address => mapping(address => uint)) private allowances; // Enforce a 1 cent minimum amount uint internal constant _MINIMUM_AMOUNT = 1e16; address public thalesAMM; bool public initialized = false; function initialize( string calldata _name, string calldata _symbol, address _thalesAMM ) external { require(!initialized, "Positional Market already initialized"); initialized = true; name = _name; symbol = _symbol; market = PositionalMarket(msg.sender); thalesAMM = _thalesAMM; } /// @notice allowance inherited IERC20 function /// @param owner address of the owner /// @param spender address of the spender /// @return uint256 number of tokens function allowance(address owner, address spender) external view override returns (uint256) { if (spender == thalesAMM) { return type(uint256).max; } else { return allowances[owner][spender]; } } /// @notice mint function mints Position token /// @param minter address of the minter /// @param amount value to mint token for function mint(address minter, uint amount) external onlyMarket { _requireMinimumAmount(amount); totalSupply = totalSupply.add(amount); balanceOf[minter] = balanceOf[minter].add(amount); // Increment rather than assigning since a transfer may have occurred. emit Transfer(address(0), minter, amount); emit Issued(minter, amount); } /// @notice exercise function exercises Position token /// @dev This must only be invoked after maturity. /// @param claimant address of the claiming address function exercise(address claimant) external onlyMarket { uint balance = balanceOf[claimant]; if (balance == 0) { return; } balanceOf[claimant] = 0; totalSupply = totalSupply.sub(balance); emit Transfer(claimant, address(0), balance); emit Burned(claimant, balance); } /// @notice exerciseWithAmount function exercises Position token /// @dev This must only be invoked after maturity. /// @param claimant address of the claiming address /// @param amount amount of tokens for exercising function exerciseWithAmount(address claimant, uint amount) external override onlyMarket { require(amount > 0, "Can not exercise zero amount!"); require(balanceOf[claimant] >= amount, "Balance must be greather or equal amount that is burned"); balanceOf[claimant] = balanceOf[claimant] - amount; totalSupply = totalSupply.sub(amount); emit Transfer(claimant, address(0), amount); emit Burned(claimant, amount); } /// @notice expire function is used for Position selfdestruct /// @dev This must only be invoked after the exercise window is complete. /// Any options which have not been exercised will linger. /// @param beneficiary address of the Position token function expire(address payable beneficiary) external onlyMarket { selfdestruct(beneficiary); } /// @notice transfer is ERC20 function for transfer tokens /// @param _to address of the receiver /// @param _value value to be transferred /// @return success function transfer(address _to, uint _value) external override returns (bool success) { return _transfer(msg.sender, _to, _value); } /// @notice transferFrom is ERC20 function for transfer tokens /// @param _from address of the sender /// @param _to address of the receiver /// @param _value value to be transferred /// @return success function transferFrom( address _from, address _to, uint _value ) external override returns (bool success) { if (msg.sender != thalesAMM) { uint fromAllowance = allowances[_from][msg.sender]; require(_value <= fromAllowance, "Insufficient allowance"); allowances[_from][msg.sender] = fromAllowance.sub(_value); } return _transfer(_from, _to, _value); } /// @notice approve is ERC20 function for token approval /// @param _spender address of the spender /// @param _value value to be approved /// @return success function approve(address _spender, uint _value) external override returns (bool success) { require(_spender != address(0)); allowances[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /// @notice getBalanceOf ERC20 function gets token balance of an account /// @param account address of the account /// @return uint function getBalanceOf(address account) external view override returns (uint) { return balanceOf[account]; } /// @notice getTotalSupply ERC20 function gets token total supply /// @return uint function getTotalSupply() external view override returns (uint) { return totalSupply; } /// @notice transfer is internal function for transfer tokens /// @param _from address of the sender /// @param _to address of the receiver /// @param _value value to be transferred /// @return success function _transfer( address _from, address _to, uint _value ) internal returns (bool success) { market.requireUnpaused(); require(_to != address(0) && _to != address(this), "Invalid address"); uint fromBalance = balanceOf[_from]; require(_value <= fromBalance, "Insufficient balance"); balanceOf[_from] = fromBalance.sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(_from, _to, _value); return true; } /// @notice _requireMinimumAmount checks that amount is greater than minimum amount /// @param amount value to be checked /// @return uint amount function _requireMinimumAmount(uint amount) internal pure returns (uint) { require(amount >= _MINIMUM_AMOUNT || amount == 0, "Balance < $0.01"); return amount; } modifier onlyMarket() { require(msg.sender == address(market), "Only market allowed"); _; } event Issued(address indexed account, uint value); event Burned(address indexed account, uint value); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // Inheritance import "../OwnedWithInit.sol"; import "../interfaces/IPositionalMarket.sol"; import "../interfaces/IOracleInstance.sol"; // Libraries import "@openzeppelin/contracts-4.4.1/utils/math/SafeMath.sol"; // Internal references import "./PositionalMarketManager.sol"; import "./Position.sol"; import "@openzeppelin/contracts-4.4.1/token/ERC20/IERC20.sol"; contract PositionalMarket is OwnedWithInit, IPositionalMarket { /* ========== LIBRARIES ========== */ using SafeMath for uint; /* ========== TYPES ========== */ struct Options { Position up; Position down; } struct Times { uint maturity; uint expiry; } struct OracleDetails { bytes32 key; uint strikePrice; uint finalPrice; bool customMarket; address iOracleInstanceAddress; } struct PositionalMarketParameters { address owner; IERC20 sUSD; IPriceFeed priceFeed; address creator; bytes32 oracleKey; uint strikePrice; uint[2] times; // [maturity, expiry] uint deposit; // sUSD deposit address up; address down; address thalesAMM; } /* ========== STATE VARIABLES ========== */ Options public options; Times public override times; OracleDetails public oracleDetails; PositionalMarketManager.Fees public override fees; IPriceFeed public priceFeed; IERC20 public sUSD; // `deposited` tracks the sum of all deposits. // This must explicitly be kept, in case tokens are transferred to the contract directly. uint public override deposited; uint public initialMint; address public override creator; bool public override resolved; /* ========== CONSTRUCTOR ========== */ bool public initialized = false; function initialize(PositionalMarketParameters calldata _parameters) external { require(!initialized, "Positional Market already initialized"); initialized = true; initOwner(_parameters.owner); sUSD = _parameters.sUSD; priceFeed = _parameters.priceFeed; creator = _parameters.creator; oracleDetails = OracleDetails(_parameters.oracleKey, _parameters.strikePrice, 0, false, address(0)); times = Times(_parameters.times[0], _parameters.times[1]); deposited = _parameters.deposit; initialMint = _parameters.deposit; // Instantiate the options themselves options.up = Position(_parameters.up); options.down = Position(_parameters.down); options.up.initialize("Position Up", "UP", _parameters.thalesAMM); options.down.initialize("Position Down", "DOWN", _parameters.thalesAMM); if (initialMint > 0) { require( !_manager().onlyAMMMintingAndBurning() || msg.sender == _manager().getThalesAMM(), "Only allowed from ThalesAMM" ); _mint(creator, initialMint); } // Note: the ERC20 base contract does not have a constructor, so we do not have to worry // about initializing its state separately } /// @notice phase returns market phase /// @return Phase function phase() external view override returns (Phase) { if (!_matured()) { return Phase.Trading; } if (!_expired()) { return Phase.Maturity; } return Phase.Expiry; } /// @notice oraclePriceAndTimestamp returns oracle key price and last updated timestamp /// @return price updatedAt function oraclePriceAndTimestamp() external view override returns (uint price, uint updatedAt) { return _oraclePriceAndTimestamp(); } /// @notice oraclePrice returns oracle key price /// @return price function oraclePrice() external view override returns (uint price) { return _oraclePrice(); } /// @notice canResolve checks if market can be resolved /// @return bool function canResolve() public view override returns (bool) { return !resolved && _matured(); } /// @notice result calculates market result based on market strike price /// @return Side function result() external view override returns (Side) { return _result(); } /// @notice balancesOf returns balances of an account /// @return up down function balancesOf(address account) external view override returns (uint up, uint down) { return _balancesOf(account); } /// @notice totalSupplies returns total supplies of op and down options /// @return up down function totalSupplies() external view override returns (uint up, uint down) { return (options.up.totalSupply(), options.down.totalSupply()); } /// @notice getMaximumBurnable returns maximum burnable amount of an account /// @param account address of the account /// @return amount function getMaximumBurnable(address account) external view override returns (uint amount) { return _getMaximumBurnable(account); } /// @notice getOptions returns up and down positions /// @return up down function getOptions() external view override returns (IPosition up, IPosition down) { up = options.up; down = options.down; } /// @notice getOracleDetails returns data from oracle source /// @return key strikePrice finalPrice function getOracleDetails() external view override returns ( bytes32 key, uint strikePrice, uint finalPrice ) { key = oracleDetails.key; strikePrice = oracleDetails.strikePrice; finalPrice = oracleDetails.finalPrice; } /// @notice requireUnpaused ensures that manager is not paused function requireUnpaused() external view { _requireManagerNotPaused(); } /// @notice mint mints up and down tokens /// @param value to mint options for function mint(uint value) external override duringMinting { require( !_manager().onlyAMMMintingAndBurning() || msg.sender == _manager().getThalesAMM(), "Only allowed from ThalesAMM" ); if (value == 0) { return; } _mint(msg.sender, value); _incrementDeposited(value); _manager().transferSusdTo(msg.sender, address(this), _manager().transformCollateral(value)); } /// @notice burnOptionsMaximum burns option tokens based on maximum burnable account amount function burnOptionsMaximum() external override { require( !_manager().onlyAMMMintingAndBurning() || msg.sender == _manager().getThalesAMM(), "Only allowed from ThalesAMM" ); _burnOptions(msg.sender, _getMaximumBurnable(msg.sender)); } /// @notice burnOptions burns option tokens based on amount function burnOptions(uint amount) external override { require( !_manager().onlyAMMMintingAndBurning() || msg.sender == _manager().getThalesAMM(), "Only allowed from ThalesAMM" ); _burnOptions(msg.sender, amount); } /// @notice resolve function for resolving market if possible function resolve() external onlyOwner afterMaturity managerNotPaused { require(canResolve(), "Can not resolve market"); uint price; uint updatedAt; (price, updatedAt) = _oraclePriceAndTimestamp(); oracleDetails.finalPrice = price; resolved = true; emit MarketResolved(_result(), price, updatedAt, deposited, 0, 0); } /// @notice exerciseOptions is used for exercising options from resolved market function exerciseOptions() external override afterMaturity returns (uint) { // The market must be resolved if it has not been. if (!resolved) { _manager().resolveMarket(address(this)); } // If the account holds no options, revert. (uint upBalance, uint downBalance) = _balancesOf(msg.sender); require(upBalance != 0 || downBalance != 0, "Nothing to exercise"); // Each option only needs to be exercised if the account holds any of it. if (upBalance != 0) { options.up.exercise(msg.sender); } if (downBalance != 0) { options.down.exercise(msg.sender); } // Only pay out the side that won. uint payout = (_result() == Side.Up) ? upBalance : downBalance; emit OptionsExercised(msg.sender, payout); if (payout != 0) { _decrementDeposited(payout); sUSD.transfer(msg.sender, _manager().transformCollateral(payout)); } return payout; } /// @notice expire is used for exercising options from resolved market function expire(address payable beneficiary) external onlyOwner { require(_expired(), "Unexpired options remaining"); emit Expired(beneficiary); _selfDestruct(beneficiary); } /// @notice _priceFeed internal function returns PriceFeed contract address /// @return IPriceFeed function _priceFeed() internal view returns (IPriceFeed) { return priceFeed; } /// @notice _manager internal function returns PositionalMarketManager contract address /// @return PositionalMarketManager function _manager() internal view returns (PositionalMarketManager) { return PositionalMarketManager(owner); } /// @notice _matured internal function checks if market is matured /// @return bool function _matured() internal view returns (bool) { return times.maturity < block.timestamp; } /// @notice _expired internal function checks if market is expired /// @return bool function _expired() internal view returns (bool) { return resolved && (times.expiry < block.timestamp || deposited == 0); } /// @notice _oraclePrice internal function returns oracle key price from source /// @return price function _oraclePrice() internal view returns (uint price) { return _priceFeed().rateForCurrency(oracleDetails.key); } /// @notice _oraclePriceAndTimestamp internal function returns oracle key price and last updated timestamp from source /// @return price updatedAt function _oraclePriceAndTimestamp() internal view returns (uint price, uint updatedAt) { return _priceFeed().rateAndUpdatedTime(oracleDetails.key); } /// @notice _result internal function calculates market result based on market strike price /// @return Side function _result() internal view returns (Side) { uint price; if (resolved) { price = oracleDetails.finalPrice; } else { price = _oraclePrice(); } return oracleDetails.strikePrice <= price ? Side.Up : Side.Down; } /// @notice _balancesOf internal function gets account balances of up and down tokens /// @param account address of an account /// @return up down function _balancesOf(address account) internal view returns (uint up, uint down) { return (options.up.getBalanceOf(account), options.down.getBalanceOf(account)); } /// @notice _getMaximumBurnable internal function gets account maximum burnable amount /// @param account address of an account /// @return amount function _getMaximumBurnable(address account) internal view returns (uint amount) { (uint upBalance, uint downBalance) = _balancesOf(account); return (upBalance > downBalance) ? downBalance : upBalance; } /// @notice _incrementDeposited internal function increments deposited value /// @param value increment value /// @return _deposited function _incrementDeposited(uint value) internal returns (uint _deposited) { _deposited = deposited.add(value); deposited = _deposited; _manager().incrementTotalDeposited(value); } /// @notice _decrementDeposited internal function decrements deposited value /// @param value decrement value /// @return _deposited function _decrementDeposited(uint value) internal returns (uint _deposited) { _deposited = deposited.sub(value); deposited = _deposited; _manager().decrementTotalDeposited(value); } /// @notice _requireManagerNotPaused internal function ensures that manager is not paused function _requireManagerNotPaused() internal view { require(!_manager().paused(), "This action cannot be performed while the contract is paused"); } /// @notice _mint internal function mints up and down tokens /// @param amount value to mint options for function _mint(address minter, uint amount) internal { options.up.mint(minter, amount); options.down.mint(minter, amount); emit Mint(Side.Up, minter, amount); emit Mint(Side.Down, minter, amount); } /// @notice _burnOptions internal function for burning up and down tokens /// @param account address of an account /// @param amount burning amount function _burnOptions(address account, uint amount) internal { require(amount > 0, "Can not burn zero amount!"); require(_getMaximumBurnable(account) >= amount, "There is not enough options!"); // decrease deposit _decrementDeposited(amount); // decrease up and down options options.up.exerciseWithAmount(account, amount); options.down.exerciseWithAmount(account, amount); // transfer balance sUSD.transfer(account, _manager().transformCollateral(amount)); // emit events emit OptionsBurned(account, amount); } /// @notice _selfDestruct internal function for market self desctruct /// @param beneficiary address of a market function _selfDestruct(address payable beneficiary) internal { uint _deposited = deposited; if (_deposited != 0) { _decrementDeposited(_deposited); } // Transfer the balance rather than the deposit value in case there are any synths left over // from direct transfers. uint balance = sUSD.balanceOf(address(this)); if (balance != 0) { sUSD.transfer(beneficiary, balance); } // Destroy the option tokens before destroying the market itself. options.up.expire(beneficiary); options.down.expire(beneficiary); selfdestruct(beneficiary); } modifier duringMinting() { require(!_matured(), "Minting inactive"); _; } modifier afterMaturity() { require(_matured(), "Not yet mature"); _; } modifier managerNotPaused() { _requireManagerNotPaused(); _; } /* ========== EVENTS ========== */ event Mint(Side side, address indexed account, uint value); event MarketResolved( Side result, uint oraclePrice, uint oracleTimestamp, uint deposited, uint poolFees, uint creatorFees ); event OptionsExercised(address indexed account, uint value); event OptionsBurned(address indexed account, uint value); event Expired(address beneficiary); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // Inheritance import "../interfaces/IPositionalMarketManager.sol"; import "../utils/proxy/solidity-0.8.0/ProxyOwned.sol"; import "../utils/proxy/solidity-0.8.0/ProxyPausable.sol"; // Libraries import "../utils/libraries/AddressSetLib.sol"; import "../utils/libraries/DateTime.sol"; import "@openzeppelin/contracts-4.4.1/utils/math/SafeMath.sol"; // Internal references import "./PositionalMarketFactory.sol"; import "./PositionalMarket.sol"; import "./Position.sol"; import "../interfaces/IPositionalMarket.sol"; import "../interfaces/IPriceFeed.sol"; import "../interfaces/IThalesAMM.sol"; import "@openzeppelin/contracts-4.4.1/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; contract PositionalMarketManager is Initializable, ProxyOwned, ProxyPausable, IPositionalMarketManager { /* ========== LIBRARIES ========== */ using SafeMath for uint; using AddressSetLib for AddressSetLib.AddressSet; /* ========== TYPES ========== */ struct Fees { uint poolFee; uint creatorFee; } struct Durations { uint expiryDuration; uint maxTimeToMaturity; } uint private constant ONE = 1e18; /* ========== STATE VARIABLES ========== */ Durations public override durations; uint public override capitalRequirement; bool public override marketCreationEnabled; bool public customMarketCreationEnabled; bool public onlyWhitelistedAddressesCanCreateMarkets; mapping(address => bool) public whitelistedAddresses; uint public override totalDeposited; AddressSetLib.AddressSet internal _activeMarkets; AddressSetLib.AddressSet internal _maturedMarkets; PositionalMarketManager internal _migratingManager; IPriceFeed public priceFeed; IERC20 public sUSD; address public positionalMarketFactory; bool public needsTransformingCollateral; uint public timeframeBuffer; uint256 public priceBuffer; mapping(bytes32 => mapping(uint => address[])) public marketsPerOracleKey; mapping(address => uint) public marketsStrikePrice; bool public override onlyAMMMintingAndBurning; uint public marketCreationMonthLimit; uint public allowedDate1; uint public allowedDate2; mapping(bytes32 => mapping(uint => mapping(uint => address))) public marketExistsByOracleKeyDateAndStrikePrice; function initialize( address _owner, IERC20 _sUSD, IPriceFeed _priceFeed, uint _expiryDuration, uint _maxTimeToMaturity ) external initializer { setOwner(_owner); priceFeed = _priceFeed; sUSD = _sUSD; // Temporarily change the owner so that the setters don't revert. owner = msg.sender; marketCreationEnabled = true; customMarketCreationEnabled = false; onlyWhitelistedAddressesCanCreateMarkets = false; setExpiryDuration(_expiryDuration); setMaxTimeToMaturity(_maxTimeToMaturity); } /// @notice isKnownMarket checks if market is among matured or active markets /// @param candidate Address of the market. /// @return bool function isKnownMarket(address candidate) public view override returns (bool) { return _activeMarkets.contains(candidate) || _maturedMarkets.contains(candidate); } /// @notice isActiveMarket checks if market is active market /// @param candidate Address of the market. /// @return bool function isActiveMarket(address candidate) public view override returns (bool) { return _activeMarkets.contains(candidate); } /// @notice numActiveMarkets returns number of active markets /// @return uint function numActiveMarkets() external view override returns (uint) { return _activeMarkets.elements.length; } /// @notice activeMarkets returns list of active markets /// @param index index of the page /// @param pageSize number of addresses per page /// @return address[] active market list function activeMarkets(uint index, uint pageSize) external view override returns (address[] memory) { return _activeMarkets.getPage(index, pageSize); } /// @notice numMaturedMarkets returns number of mature markets /// @return uint function numMaturedMarkets() external view override returns (uint) { return _maturedMarkets.elements.length; } /// @notice maturedMarkets returns list of matured markets /// @param index index of the page /// @param pageSize number of addresses per page /// @return address[] matured market list function maturedMarkets(uint index, uint pageSize) external view override returns (address[] memory) { return _maturedMarkets.getPage(index, pageSize); } /// @notice incrementTotalDeposited increments totalDeposited value /// @param delta increment amount function incrementTotalDeposited(uint delta) external onlyActiveMarkets notPaused { totalDeposited = totalDeposited.add(delta); } /// @notice decrementTotalDeposited decrements totalDeposited value /// @dev As individual market debt is not tracked here, the underlying markets /// need to be careful never to subtract more debt than they added. /// This can't be enforced without additional state/communication overhead. /// @param delta decrement amount function decrementTotalDeposited(uint delta) external onlyKnownMarkets notPaused { totalDeposited = totalDeposited.sub(delta); } /// @notice createMarket create market function /// @param oracleKey market oracle key /// @param strikePrice market strike price /// @param maturity market maturity date /// @param initialMint initial sUSD to mint options for /// @return IPositionalMarket created market function createMarket( bytes32 oracleKey, uint strikePrice, uint maturity, uint initialMint ) external override notPaused returns ( IPositionalMarket // no support for returning PositionalMarket polymorphically given the interface ) { return _createMarket(oracleKey, strikePrice, maturity, initialMint); } /// @notice createMarkest creates multiple markets /// @param oracleKeys market oracle key /// @param strikePrices market strike price /// @param maturities market maturity date function createMarkets( bytes32[] calldata oracleKeys, uint[] calldata strikePrices, uint[] calldata maturities ) external notPaused { require( oracleKeys.length > 0 && oracleKeys.length == strikePrices.length && oracleKeys.length == maturities.length, "All arrays have to be non-empty and same size" ); for (uint i = 0; i < oracleKeys.length; i++) { (bool canCreate, string memory message) = canCreateMarket(oracleKeys[i], maturities[i], strikePrices[i]); if (canCreate) { _createMarket(oracleKeys[i], strikePrices[i], maturities[i], 0); } } } /// @notice transferSusdTo transfers sUSD from market to receiver /// @dev Only to be called by markets themselves /// @param sender address of sender /// @param receiver address of receiver /// @param amount amount to be transferred function transferSusdTo( address sender, address receiver, uint amount ) external override { //only to be called by markets themselves require(isKnownMarket(address(msg.sender)), "Market unknown."); amount = needsTransformingCollateral ? amount + 1 : amount; bool success = sUSD.transferFrom(sender, receiver, amount); if (!success) { revert("TransferFrom function failed"); } } /// @notice resolveMarket resolves an active market /// @param market address of the market function resolveMarket(address market) external override { require(_activeMarkets.contains(market), "Not an active market"); PositionalMarket(market).resolve(); _activeMarkets.remove(market); _maturedMarkets.add(market); } /// @notice resolveMarketsBatch resolve all markets in the batch /// @param markets the batch function resolveMarketsBatch(address[] calldata markets) external { for (uint i = 0; i < markets.length; i++) { address market = markets[i]; if (_activeMarkets.contains(market)) { PositionalMarket(market).resolve(); _activeMarkets.remove(market); _maturedMarkets.add(market); } } } /// @notice expireMarkets removes expired markets from matured markets /// @param markets array of market addresses function expireMarkets(address[] calldata markets) external override notPaused onlyOwner { for (uint i = 0; i < markets.length; i++) { address market = markets[i]; require(isKnownMarket(address(market)), "Market unknown."); // The market itself handles decrementing the total deposits. PositionalMarket(market).expire(payable(msg.sender)); // Note that we required that the market is known, which guarantees // its index is defined and that the list of markets is not empty. _maturedMarkets.remove(market); emit MarketExpired(market); } } /// @notice transformCollateral transforms collateral /// @param value value to be transformed /// @return uint function transformCollateral(uint value) external view override returns (uint) { return _transformCollateral(value); } /// @notice reverseTransformCollateral reverse collateral if needed /// @param value value to be reversed /// @return uint function reverseTransformCollateral(uint value) external view override returns (uint) { if (needsTransformingCollateral) { return value * 1e12; } else { return value; } } /// @notice canCreateMarket checks if market can be created /// @param oracleKey market oracle key /// @param maturity market maturity timestamp /// @param strikePrice market strike price /// @return bool function canCreateMarket( bytes32 oracleKey, uint maturity, uint strikePrice ) public view returns (bool, string memory) { if (!marketCreationEnabled) { return (false, "Market creation is disabled"); } if (!_isValidKey(oracleKey)) { return (false, "Invalid key"); } if (maturity > block.timestamp + durations.maxTimeToMaturity) { return (false, "Maturity too far in the future"); } if (block.timestamp >= maturity) { return (false, "Maturity cannot be in the past"); } if (marketExistsByOracleKeyDateAndStrikePrice[oracleKey][maturity][strikePrice] != address(0)) { return (false, "Market already exists"); } uint strikePriceStep = getStrikePriceStep(oracleKey); uint currentAssetPrice = priceFeed.rateForCurrency(oracleKey); if (strikePriceStep != 0 && strikePrice % strikePriceStep != 0) { return (false, "Invalid strike price"); } uint dateDiff1 = (maturity - allowedDate1) % 604800; uint dateDiff2 = (maturity - allowedDate2) % 604800; if (!(dateDiff1 == 0 || dateDiff2 == 0)) { return (false, "Invalid maturity"); } return (true, ""); } /// @notice enableWhitelistedAddresses enables option that only whitelisted addresses /// can create markets function enableWhitelistedAddresses() external onlyOwner { onlyWhitelistedAddressesCanCreateMarkets = true; } /// @notice disableWhitelistedAddresses disables option that only whitelisted addresses /// can create markets function disableWhitelistedAddresses() external onlyOwner { onlyWhitelistedAddressesCanCreateMarkets = false; } /// @notice addWhitelistedAddress adds given address to whitelisted addresses list /// @param _address address to be added to the list function addWhitelistedAddress(address _address) external onlyOwner { whitelistedAddresses[_address] = true; } /// @notice removeWhitelistedAddress removes given address from whitelisted addresses list /// @param _address address to be removed from the list function removeWhitelistedAddress(address _address) external onlyOwner { delete whitelistedAddresses[_address]; } /// @notice setWhitelistedAddresses enables whitelist addresses option and creates list /// @param _whitelistedAddresses array of whitelisted addresses function setWhitelistedAddresses(address[] calldata _whitelistedAddresses) external onlyOwner { require(_whitelistedAddresses.length > 0, "Whitelisted addresses cannot be empty"); onlyWhitelistedAddressesCanCreateMarkets = true; for (uint256 index = 0; index < _whitelistedAddresses.length; index++) { whitelistedAddresses[_whitelistedAddresses[index]] = true; } } /// @notice setPositionalMarketFactory sets PositionalMarketFactory address /// @param _positionalMarketFactory address of PositionalMarketFactory function setPositionalMarketFactory(address _positionalMarketFactory) external onlyOwner { positionalMarketFactory = _positionalMarketFactory; emit SetPositionalMarketFactory(_positionalMarketFactory); } /// @notice setNeedsTransformingCollateral sets needsTransformingCollateral value /// @param _needsTransformingCollateral boolen value to be set function setNeedsTransformingCollateral(bool _needsTransformingCollateral) external onlyOwner { needsTransformingCollateral = _needsTransformingCollateral; } /// @notice setExpiryDuration sets expiryDuration value /// @param _expiryDuration value in seconds needed for market expiry check function setExpiryDuration(uint _expiryDuration) public onlyOwner { durations.expiryDuration = _expiryDuration; emit ExpiryDurationUpdated(_expiryDuration); } /// @notice setMaxTimeToMaturity sets maxTimeToMaturity value /// @param _maxTimeToMaturity value in seconds for market max time to maturity check function setMaxTimeToMaturity(uint _maxTimeToMaturity) public onlyOwner { durations.maxTimeToMaturity = _maxTimeToMaturity; emit MaxTimeToMaturityUpdated(_maxTimeToMaturity); } /// @notice setPriceFeed sets address of PriceFeed contract /// @param _address PriceFeed address function setPriceFeed(address _address) external onlyOwner { priceFeed = IPriceFeed(_address); emit SetPriceFeed(_address); } /// @notice setOnlyAMMMintingAndBurning whether minting and burning is only allowed for AMM /// @param _onlyAMMMintingAndBurning the value function setOnlyAMMMintingAndBurning(bool _onlyAMMMintingAndBurning) external onlyOwner { onlyAMMMintingAndBurning = _onlyAMMMintingAndBurning; emit SetOnlyAMMMintingAndBurning(_onlyAMMMintingAndBurning); } /// @notice setsUSD sets address of sUSD contract /// @param _address sUSD address function setsUSD(address _address) external onlyOwner { sUSD = IERC20(_address); emit SetsUSD(_address); } /// @notice setPriceBuffer sets priceBuffer value /// @param _priceBuffer value in percents needed for market creaton check function setPriceBuffer(uint _priceBuffer) external onlyOwner { priceBuffer = _priceBuffer; emit PriceBufferChanged(_priceBuffer); } /// @notice setTimeframeBuffer sets timeframeBuffer value /// @param _timeframeBuffer value in days needed for market creaton check function setTimeframeBuffer(uint _timeframeBuffer) external onlyOwner { timeframeBuffer = _timeframeBuffer; emit TimeframeBufferChanged(_timeframeBuffer); } /// @notice setMarketCreationEnabled sets marketCreationEnabled value /// @param enabled boolean value to enable/disable market creation function setMarketCreationEnabled(bool enabled) external onlyOwner { if (enabled != marketCreationEnabled) { marketCreationEnabled = enabled; emit MarketCreationEnabledUpdated(enabled); } } /// @notice setMarketCreationParameters sets params for market creation /// @param _allowedDate1 timestamp to be compared with strike date /// @param _allowedDate2 timestamp to be compared with strike date function setMarketCreationParameters(uint _allowedDate1, uint _allowedDate2) external onlyOwner { allowedDate1 = _allowedDate1; allowedDate2 = _allowedDate2; emit MarketCreationParametersChanged(_allowedDate1, _allowedDate2); } /// @notice getStrikePriceStep calculates strike price step /// @param oracleKey oracle key function getStrikePriceStep(bytes32 oracleKey) public view returns (uint result) { if (_getImpliedVolatility(oracleKey) == 0) return 0; uint strikePriceStep = (priceFeed.rateForCurrency(oracleKey) * _getImpliedVolatility(oracleKey)) / (2000 * ONE); uint exponent = _getExponent(strikePriceStep); uint8[3] memory indexArray = [1, 2, 3]; uint tempMultiplier = _calculateStrikePriceStepMultiplier(strikePriceStep, exponent, exponent); for (uint i = 0; i < indexArray.length; i++) { result = _calculateStrikePriceStepValue(indexArray[i], tempMultiplier); if (strikePriceStep > result && i != (indexArray.length - 1)) { continue; } else if (strikePriceStep > result && i == (indexArray.length - 1)) { tempMultiplier = _calculateStrikePriceStepMultiplier( strikePriceStep, exponent + 1, exponent == 0 ? exponent : exponent - 1 ); uint nextResult = _calculateStrikePriceStepValue(indexArray[0], tempMultiplier); if (strikePriceStep - result > nextResult - strikePriceStep) { result = nextResult; } break; } else { uint prevResult = 0; if (i == 0) { tempMultiplier = _calculateStrikePriceStepMultiplier(strikePriceStep, exponent - 1, exponent + 1); prevResult = _calculateStrikePriceStepValue(indexArray[2], tempMultiplier); } else { prevResult = _calculateStrikePriceStepValue(indexArray[i - 1], tempMultiplier); } if (result - strikePriceStep > strikePriceStep - prevResult) { result = prevResult; } break; } } } function _createMarket( bytes32 oracleKey, uint strikePrice, uint maturity, uint initialMint ) internal returns ( IPositionalMarket // no support for returning PositionalMarket polymorphically given the interface ) { if (onlyWhitelistedAddressesCanCreateMarkets) { require(whitelistedAddresses[msg.sender], "Only whitelisted addresses can create markets"); } (bool canCreate, string memory message) = canCreateMarket(oracleKey, maturity, strikePrice); require(canCreate, message); uint expiry = maturity.add(durations.expiryDuration); PositionalMarket market = PositionalMarketFactory(positionalMarketFactory).createMarket( PositionalMarketFactory.PositionCreationMarketParameters( msg.sender, sUSD, priceFeed, oracleKey, strikePrice, [maturity, expiry], initialMint ) ); _activeMarkets.add(address(market)); // The debt can't be incremented in the new market's constructor because until construction is complete, // the manager doesn't know its address in order to grant it permission. totalDeposited = totalDeposited.add(initialMint); sUSD.transferFrom(msg.sender, address(market), _transformCollateral(initialMint)); (IPosition up, IPosition down) = market.getOptions(); marketExistsByOracleKeyDateAndStrikePrice[oracleKey][maturity][strikePrice] = address(market); emit MarketCreated( address(market), msg.sender, oracleKey, strikePrice, maturity, expiry, address(up), address(down), false, address(0) ); return market; } /// @notice _calculateStrikePriceStepValue calculates strike price step via formulae /// @param index index value /// @param multiplier multiplier value function _calculateStrikePriceStepValue(uint index, uint multiplier) internal pure returns (uint value) { value = (2**index - index) * multiplier; } /// @notice _calculateStrikePriceStepValue helper function for calculating strike price step /// @param strikePriceStep initial strike price step /// @param exponent1 exponent if strikePriceStep >= 1 /// @param exponent2 exponent if strikePriceStep < 1 function _calculateStrikePriceStepMultiplier( uint strikePriceStep, uint exponent1, uint exponent2 ) internal pure returns (uint value) { value = strikePriceStep >= ONE ? 10**exponent1 * ONE : ONE / (10**exponent2); } /// @notice _getExponent helper function for calculating exponent of strike price step /// @param strikePriceStep initial strike price step function _getExponent(uint strikePriceStep) internal pure returns (uint exponent) { if (strikePriceStep >= ONE) { while (strikePriceStep > ONE) { strikePriceStep /= 10; exponent += 1; } exponent -= 1; } else { while (strikePriceStep < ONE) { strikePriceStep *= 10; exponent += 1; } } } /// @notice _isValidKey checks if oracle key is supported by PriceFeed contract /// @param oracleKey oracle key /// @return bool function _isValidKey(bytes32 oracleKey) internal view returns (bool) { // If it has a rate, then it's possibly a valid key if (priceFeed.rateForCurrency(oracleKey) != 0) { return true; } return false; } /// @notice _getImpliedVolatility gets implied volatility per asset from ThalesAMM contract /// @param oracleKey asset to fetch value for /// @return impliedVolatility function _getImpliedVolatility(bytes32 oracleKey) internal view returns (uint impliedVolatility) { address thalesAMM = PositionalMarketFactory(positionalMarketFactory).thalesAMM(); impliedVolatility = IThalesAMM(thalesAMM).impliedVolatilityPerAsset(oracleKey); } /// @notice get the thales amm address from the factory /// @return thales amm address function getThalesAMM() external view override returns (address) { return PositionalMarketFactory(positionalMarketFactory).thalesAMM(); } /// @notice _transformCollateral transforms collateral if needed /// @param value value to be transformed /// @return uint function _transformCollateral(uint value) internal view returns (uint) { if (needsTransformingCollateral) { return value / 1e12; } else { return value; } } modifier onlyActiveMarkets() { require(_activeMarkets.contains(msg.sender), "Permitted only for active markets."); _; } modifier onlyKnownMarkets() { require(isKnownMarket(msg.sender), "Permitted only for known markets."); _; } event MarketCreated( address market, address indexed creator, bytes32 indexed oracleKey, uint strikePrice, uint maturityDate, uint expiryDate, address up, address down, bool customMarket, address customOracle ); event MarketExpired(address market); event MarketsMigrated(PositionalMarketManager receivingManager, PositionalMarket[] markets); event MarketsReceived(PositionalMarketManager migratingManager, PositionalMarket[] markets); event MarketCreationEnabledUpdated(bool enabled); event ExpiryDurationUpdated(uint duration); event MaxTimeToMaturityUpdated(uint duration); event SetPositionalMarketFactory(address _positionalMarketFactory); event SetZeroExAddress(address _zeroExAddress); event SetPriceFeed(address _address); event SetsUSD(address _address); event SetMigratingManager(address manager); event PriceBufferChanged(uint priceBuffer); event TimeframeBufferChanged(uint timeframeBuffer); event SetOnlyAMMMintingAndBurning(bool _SetOnlyAMMMintingAndBurning); event MarketCreationParametersChanged(uint _allowedDate1, uint _allowedDate2); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts-4.4.1/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts-4.4.1/token/ERC20/utils/SafeERC20.sol"; // Internal references import "./RangedPosition.sol"; import "./RangedMarketsAMM.sol"; import "../interfaces/IPositionalMarket.sol"; import "../interfaces/IPositionalMarketManager.sol"; contract RangedMarket { using SafeERC20 for IERC20; enum Position {In, Out} IPositionalMarket public leftMarket; IPositionalMarket public rightMarket; struct Positions { RangedPosition inp; RangedPosition outp; } Positions public positions; RangedMarketsAMM public rangedMarketsAMM; bool public resolved = false; uint finalPrice; /* ========== CONSTRUCTOR ========== */ bool public initialized = false; function initialize( address _leftMarket, address _rightMarket, address _in, address _out, address _rangedMarketsAMM ) external { require(!initialized, "Ranged Market already initialized"); initialized = true; leftMarket = IPositionalMarket(_leftMarket); rightMarket = IPositionalMarket(_rightMarket); positions.inp = RangedPosition(_in); positions.outp = RangedPosition(_out); rangedMarketsAMM = RangedMarketsAMM(_rangedMarketsAMM); } function mint( uint value, Position _position, address minter ) external onlyAMM { if (value == 0) { return; } _mint(minter, value, _position); } function _mint( address minter, uint amount, Position _position ) internal { if (_position == Position.In) { positions.inp.mint(minter, amount); } else { positions.outp.mint(minter, amount); } emit Mint(minter, amount, _position); } function burnIn(uint value, address claimant) external onlyAMM { if (value == 0) { return; } (IPosition up, ) = IPositionalMarket(leftMarket).getOptions(); IERC20(address(up)).safeTransfer(msg.sender, value / 2); (, IPosition down1) = IPositionalMarket(rightMarket).getOptions(); IERC20(address(down1)).safeTransfer(msg.sender, value / 2); positions.inp.burn(claimant, value); emit Burn(claimant, value, Position.In); } function burnOut(uint value, address claimant) external onlyAMM { if (value == 0) { return; } (, IPosition down) = IPositionalMarket(leftMarket).getOptions(); IERC20(address(down)).safeTransfer(msg.sender, value); (IPosition up1, ) = IPositionalMarket(rightMarket).getOptions(); IERC20(address(up1)).safeTransfer(msg.sender, value); positions.outp.burn(claimant, value); emit Burn(claimant, value, Position.Out); } function canExercisePositions() external view returns (bool) { if (!leftMarket.resolved() && !leftMarket.canResolve()) { return false; } if (!rightMarket.resolved() && !rightMarket.canResolve()) { return false; } uint inBalance = positions.inp.balanceOf(msg.sender); uint outBalance = positions.outp.balanceOf(msg.sender); if (inBalance == 0 && outBalance == 0) { return false; } return true; } function exercisePositions() external { if (leftMarket.canResolve()) { IPositionalMarketManager(rangedMarketsAMM.thalesAmm().manager()).resolveMarket(address(leftMarket)); } if (rightMarket.canResolve()) { IPositionalMarketManager(rangedMarketsAMM.thalesAmm().manager()).resolveMarket(address(rightMarket)); } require(leftMarket.resolved() && rightMarket.resolved(), "Left or Right market not resolved yet!"); uint inBalance = positions.inp.balanceOf(msg.sender); uint outBalance = positions.outp.balanceOf(msg.sender); require(inBalance != 0 || outBalance != 0, "Nothing to exercise"); if (!resolved) { resolveMarket(); } // Each option only needs to be exercised if the account holds any of it. if (inBalance != 0) { positions.inp.burn(msg.sender, inBalance); } if (outBalance != 0) { positions.outp.burn(msg.sender, outBalance); } Position curResult = Position.Out; if ((leftMarket.result() == IPositionalMarket.Side.Up) && (rightMarket.result() == IPositionalMarket.Side.Down)) { curResult = Position.In; } // Only pay out the side that won. uint payout = (curResult == Position.In) ? inBalance : outBalance; if (payout != 0) { rangedMarketsAMM.transferSusdTo( msg.sender, IPositionalMarketManager(rangedMarketsAMM.thalesAmm().manager()).transformCollateral(payout) ); } emit Exercised(msg.sender, payout, curResult); } function canResolve() external view returns (bool) { // The markets must be resolved if (!leftMarket.resolved() && !leftMarket.canResolve()) { return false; } if (!rightMarket.resolved() && !rightMarket.canResolve()) { return false; } return !resolved; } function resolveMarket() public { // The markets must be resolved if (leftMarket.canResolve()) { IPositionalMarketManager(rangedMarketsAMM.thalesAmm().manager()).resolveMarket(address(leftMarket)); } if (rightMarket.canResolve()) { IPositionalMarketManager(rangedMarketsAMM.thalesAmm().manager()).resolveMarket(address(rightMarket)); } require(leftMarket.resolved() && rightMarket.resolved(), "Left or Right market not resolved yet!"); require(!resolved, "Already resolved!"); if (positions.inp.totalSupply() > 0 || positions.outp.totalSupply() > 0) { leftMarket.exerciseOptions(); rightMarket.exerciseOptions(); } resolved = true; if (rangedMarketsAMM.sUSD().balanceOf(address(this)) > 0) { rangedMarketsAMM.sUSD().transfer(address(rangedMarketsAMM), rangedMarketsAMM.sUSD().balanceOf(address(this))); } (, , uint _finalPrice) = leftMarket.getOracleDetails(); finalPrice = _finalPrice; emit Resolved(result(), finalPrice); } function result() public view returns (Position resultToReturn) { resultToReturn = Position.Out; if ((leftMarket.result() == IPositionalMarket.Side.Up) && (rightMarket.result() == IPositionalMarket.Side.Down)) { resultToReturn = Position.In; } } function withdrawCollateral(address recipient) external onlyAMM { rangedMarketsAMM.sUSD().transfer(recipient, rangedMarketsAMM.sUSD().balanceOf(address(this))); } modifier onlyAMM { require(msg.sender == address(rangedMarketsAMM), "only the AMM may perform these methods"); _; } event Mint(address minter, uint amount, Position _position); event Burn(address burner, uint amount, Position _position); event Exercised(address exerciser, uint amount, Position _position); event Resolved(Position winningPosition, uint finalPrice); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // external import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; import "@openzeppelin/contracts-4.4.1/proxy/Clones.sol"; // interfaces import "../interfaces/IPriceFeed.sol"; import "../interfaces/IThalesAMM.sol"; // internal import "../utils/proxy/solidity-0.8.0/ProxyReentrancyGuard.sol"; import "../utils/proxy/solidity-0.8.0/ProxyOwned.sol"; import "../utils/proxy/solidity-0.8.0/ProxyPausable.sol"; import "../utils/libraries/AddressSetLib.sol"; import "./RangedPosition.sol"; import "./RangedPosition.sol"; import "./RangedMarket.sol"; import "../interfaces/IPositionalMarket.sol"; import "../interfaces/IStakingThales.sol"; import "../interfaces/IReferrals.sol"; import "../interfaces/ICurveSUSD.sol"; contract RangedMarketsAMM is Initializable, ProxyOwned, ProxyPausable, ProxyReentrancyGuard { using AddressSetLib for AddressSetLib.AddressSet; using SafeERC20Upgradeable for IERC20Upgradeable; uint private constant ONE = 1e18; uint private constant ONE_PERCENT = 1e16; IThalesAMM public thalesAmm; uint public rangedAmmFee; mapping(address => mapping(address => address)) public createdRangedMarkets; AddressSetLib.AddressSet internal _knownMarkets; address public rangedMarketMastercopy; address public rangedPositionMastercopy; IERC20Upgradeable public sUSD; mapping(address => uint) public spentOnMarket; // IMPORTANT: AMM risks only half or the payout effectively, but it risks the whole amount on price movements uint public capPerMarket; uint public minSupportedPrice; uint public maxSupportedPrice; address public safeBox; uint public safeBoxImpact; uint public minimalDifBetweenStrikes; IStakingThales public stakingThales; uint public maximalDifBetweenStrikes; address public referrals; uint public referrerFee; ICurveSUSD public curveSUSD; address public usdc; address public usdt; address public dai; bool public curveOnrampEnabled; uint public maxAllowedPegSlippagePercentage; function initialize( address _owner, IThalesAMM _thalesAmm, uint _rangedAmmFee, uint _capPerMarket, IERC20Upgradeable _sUSD, address _safeBox, uint _safeBoxImpact ) public initializer { setOwner(_owner); initNonReentrant(); thalesAmm = _thalesAmm; capPerMarket = _capPerMarket; rangedAmmFee = _rangedAmmFee; sUSD = _sUSD; safeBox = _safeBox; safeBoxImpact = _safeBoxImpact; sUSD.approve(address(thalesAmm), type(uint256).max); } function createRangedMarket(address leftMarket, address rightMarket) external nonReentrant notPaused { _createRangedMarket(leftMarket, rightMarket); } function createRangedMarkets(address[] calldata leftMarkets, address[] calldata rightMarkets) external nonReentrant notPaused { require( leftMarkets.length > 0 && rightMarkets.length == leftMarkets.length, "Both arrays have to be non-empty and same size" ); for (uint i = 0; i < leftMarkets.length; i++) { if (canCreateRangedMarket(leftMarkets[i], rightMarkets[i])) { _createRangedMarket(leftMarkets[i], rightMarkets[i]); } } } function canCreateRangedMarket(address leftMarket, address rightMarket) public view returns (bool toReturn) { if (thalesAmm.isMarketInAMMTrading(leftMarket) && thalesAmm.isMarketInAMMTrading(rightMarket)) { (uint maturityLeft, ) = IPositionalMarket(leftMarket).times(); (uint maturityRight, ) = IPositionalMarket(rightMarket).times(); (bytes32 leftkey, uint leftstrikePrice, ) = IPositionalMarket(leftMarket).getOracleDetails(); (bytes32 rightkey, uint rightstrikePrice, ) = IPositionalMarket(rightMarket).getOracleDetails(); if ((leftkey == rightkey) && (leftstrikePrice < rightstrikePrice) && (maturityLeft == maturityRight)) { if (!(((ONE + minimalDifBetweenStrikes * ONE_PERCENT) * leftstrikePrice) / ONE < rightstrikePrice)) { toReturn = false; } else if (!(((ONE + maximalDifBetweenStrikes * ONE_PERCENT) * leftstrikePrice) / ONE > rightstrikePrice)) { toReturn = false; } else { toReturn = createdRangedMarkets[leftMarket][rightMarket] == address(0); } } } } function availableToBuyFromAMM(RangedMarket rangedMarket, RangedMarket.Position position) public view knownRangedMarket(address(rangedMarket)) returns (uint) { uint availableLeft = thalesAmm.availableToBuyFromAMM( address(rangedMarket.leftMarket()), position == RangedMarket.Position.Out ? IThalesAMM.Position.Down : IThalesAMM.Position.Up ); uint availableRight = thalesAmm.availableToBuyFromAMM( address(rangedMarket.rightMarket()), position == RangedMarket.Position.Out ? IThalesAMM.Position.Up : IThalesAMM.Position.Down ); return availableLeft < availableRight ? availableLeft : availableRight; } function buyFromAmmQuote( RangedMarket rangedMarket, RangedMarket.Position position, uint amount ) public view knownRangedMarket(address(rangedMarket)) returns (uint sUSDPaid) { (sUSDPaid, , ) = buyFromAmmQuoteDetailed(rangedMarket, position, amount); uint basePrice = _transformCollateral((sUSDPaid * ONE) / amount, true); if (basePrice < minSupportedPrice || basePrice >= ONE) { sUSDPaid = 0; } } function buyFromAmmQuoteDetailed( RangedMarket rangedMarket, RangedMarket.Position position, uint amount ) public view knownRangedMarket(address(rangedMarket)) returns ( uint quoteWithFees, uint leftQuote, uint rightQuote ) { amount = position == RangedMarket.Position.Out ? amount : amount / 2; leftQuote = thalesAmm.buyFromAmmQuote( address(rangedMarket.leftMarket()), position == RangedMarket.Position.Out ? IThalesAMM.Position.Down : IThalesAMM.Position.Up, amount ); rightQuote = thalesAmm.buyFromAmmQuote( address(rangedMarket.rightMarket()), position == RangedMarket.Position.Out ? IThalesAMM.Position.Up : IThalesAMM.Position.Down, amount ); quoteWithFees = _buyFromAmmQuoteWithLeftAndRightQuote(position, amount, leftQuote, rightQuote); } function buyFromAmmQuoteWithDifferentCollateral( RangedMarket rangedMarket, RangedMarket.Position position, uint amount, address collateral ) public view returns (uint collateralQuote, uint sUSDToPay) { int128 curveIndex = _mapCollateralToCurveIndex(collateral); if (curveIndex > 0 && curveOnrampEnabled) { sUSDToPay = buyFromAmmQuote(rangedMarket, position, amount); //cant get a quote on how much collateral is needed from curve for sUSD, //so rather get how much of collateral you get for the sUSD quote and add 0.2% to that collateralQuote = (curveSUSD.get_dy_underlying(0, curveIndex, sUSDToPay) * (ONE + (ONE_PERCENT / 5))) / ONE; } } function buyFromAMMWithReferrer( RangedMarket rangedMarket, RangedMarket.Position position, uint amount, uint expectedPayout, uint additionalSlippage, address referrer ) public knownRangedMarket(address(rangedMarket)) nonReentrant notPaused { if (referrer != address(0)) { IReferrals(referrals).setReferrer(referrer, msg.sender); } _buyFromAMM(rangedMarket, position, amount, expectedPayout, additionalSlippage, true); } function buyFromAMMWithDifferentCollateralAndReferrer( RangedMarket rangedMarket, RangedMarket.Position position, uint amount, uint expectedPayout, uint additionalSlippage, address collateral, address _referrer ) public nonReentrant notPaused { if (_referrer != address(0)) { IReferrals(referrals).setReferrer(_referrer, msg.sender); } int128 curveIndex = _mapCollateralToCurveIndex(collateral); require(curveIndex > 0 && curveOnrampEnabled, "ID1"); (uint collateralQuote, uint susdQuote) = buyFromAmmQuoteWithDifferentCollateral( rangedMarket, position, amount, collateral ); uint transformedCollateralForPegCheck = collateral == usdc || collateral == usdt ? collateralQuote * 1e12 : collateralQuote; require( maxAllowedPegSlippagePercentage > 0 && transformedCollateralForPegCheck >= (susdQuote * (ONE - maxAllowedPegSlippagePercentage)) / ONE, "ID3" ); require((collateralQuote * ONE) / expectedPayout <= (ONE + additionalSlippage), "ID2"); IERC20Upgradeable(collateral).safeTransferFrom(msg.sender, address(this), collateralQuote); curveSUSD.exchange_underlying(curveIndex, 0, collateralQuote, susdQuote); _buyFromAMM(rangedMarket, position, amount, susdQuote, additionalSlippage, false); } function buyFromAMM( RangedMarket rangedMarket, RangedMarket.Position position, uint amount, uint expectedPayout, uint additionalSlippage ) public knownRangedMarket(address(rangedMarket)) nonReentrant notPaused { _buyFromAMM(rangedMarket, position, amount, expectedPayout, additionalSlippage, true); } function _buyFromAmmQuoteWithLeftAndRightQuote( RangedMarket.Position position, uint amount, uint leftQuote, uint rightQuote ) internal view returns (uint quoteWithFees) { if (leftQuote > 0 && rightQuote > 0) { uint summedQuotes = leftQuote + rightQuote; if (position == RangedMarket.Position.Out) { quoteWithFees = (summedQuotes * (rangedAmmFee + ONE)) / ONE; } else { if ( summedQuotes > ((_transformCollateral(amount, false) - leftQuote) + (_transformCollateral(amount, false) - rightQuote)) ) { uint quoteWithoutFees = summedQuotes - (_transformCollateral(amount, false) - leftQuote) - (_transformCollateral(amount, false) - rightQuote); quoteWithFees = (quoteWithoutFees * (rangedAmmFee + safeBoxImpact + ONE)) / ONE; } } } } function _buyFromAMM( RangedMarket rangedMarket, RangedMarket.Position position, uint amount, uint expectedPayout, uint additionalSlippage, bool sendSUSD ) internal { require(availableToBuyFromAMM(rangedMarket, position) >= amount, "ID4"); uint sUSDPaid; address target; (RangedPosition inp, RangedPosition outp) = rangedMarket.positions(); if (position == RangedMarket.Position.Out) { target = address(outp); sUSDPaid = _buyOUT(rangedMarket, amount); } else { target = address(inp); sUSDPaid = _buyIN(rangedMarket, amount); _handleSafeBoxFeeOnBuy(address(rangedMarket), amount, sUSDPaid); } uint basePrice = _transformCollateral((sUSDPaid * ONE) / amount, true); require(basePrice > minSupportedPrice && basePrice < ONE, "ID5"); require(sUSDPaid > 0 && ((sUSDPaid * ONE) / expectedPayout <= (ONE + additionalSlippage)), "ID2"); if (sendSUSD) { sUSD.safeTransferFrom(msg.sender, address(this), sUSDPaid); } rangedMarket.mint(amount, position, msg.sender); _handleReferrer(msg.sender, sUSDPaid); if (address(stakingThales) != address(0)) { stakingThales.updateVolume(msg.sender, sUSDPaid); } emit BoughtFromAmm(msg.sender, address(rangedMarket), position, amount, sUSDPaid, address(sUSD), target); (bytes32 leftkey, uint leftstrikePrice, ) = IPositionalMarket(rangedMarket.leftMarket()).getOracleDetails(); (, uint rightstrikePrice, ) = IPositionalMarket(rangedMarket.rightMarket()).getOracleDetails(); uint currentAssetPrice = thalesAmm.priceFeed().rateForCurrency(leftkey); bool inTheMoney = position == RangedMarket.Position.In ? currentAssetPrice >= leftstrikePrice && currentAssetPrice < rightstrikePrice : currentAssetPrice < leftstrikePrice || currentAssetPrice >= rightstrikePrice; emit BoughtOptionType(msg.sender, sUSDPaid, inTheMoney); } function _buyOUT(RangedMarket rangedMarket, uint amount) internal returns (uint) { uint paidLeft = thalesAmm.buyFromAMM( address(rangedMarket.leftMarket()), IThalesAMM.Position.Down, amount, type(uint256).max, 0 ); uint paidRight = thalesAmm.buyFromAMM( address(rangedMarket.rightMarket()), IThalesAMM.Position.Up, amount, type(uint256).max, 0 ); (, IPosition down) = IPositionalMarket(rangedMarket.leftMarket()).getOptions(); IERC20Upgradeable(address(down)).safeTransfer(address(rangedMarket), amount); (IPosition up1, ) = IPositionalMarket(rangedMarket.rightMarket()).getOptions(); IERC20Upgradeable(address(up1)).safeTransfer(address(rangedMarket), amount); return _buyFromAmmQuoteWithLeftAndRightQuote(RangedMarket.Position.Out, amount, paidLeft, paidRight); } function _buyIN(RangedMarket rangedMarket, uint amount) internal returns (uint) { uint paidLeft = thalesAmm.buyFromAMM( address(rangedMarket.leftMarket()), IThalesAMM.Position.Up, amount / 2, type(uint256).max, 0 ); uint paidRight = thalesAmm.buyFromAMM( address(rangedMarket.rightMarket()), IThalesAMM.Position.Down, amount / 2, type(uint256).max, 0 ); (IPosition up, ) = IPositionalMarket(rangedMarket.leftMarket()).getOptions(); IERC20Upgradeable(address(up)).safeTransfer(address(rangedMarket), amount / 2); (, IPosition down1) = IPositionalMarket(rangedMarket.rightMarket()).getOptions(); IERC20Upgradeable(address(down1)).safeTransfer(address(rangedMarket), amount / 2); return _buyFromAmmQuoteWithLeftAndRightQuote(RangedMarket.Position.In, amount / 2, paidLeft, paidRight); } function availableToSellToAMM(RangedMarket rangedMarket, RangedMarket.Position position) public view knownRangedMarket(address(rangedMarket)) returns (uint _available) { uint availableLeft = thalesAmm.availableToSellToAMM( address(rangedMarket.leftMarket()), position == RangedMarket.Position.Out ? IThalesAMM.Position.Down : IThalesAMM.Position.Up ); uint availableRight = thalesAmm.availableToSellToAMM( address(rangedMarket.rightMarket()), position == RangedMarket.Position.Out ? IThalesAMM.Position.Up : IThalesAMM.Position.Down ); _available = availableLeft < availableRight ? availableLeft : availableRight; if (position == RangedMarket.Position.In) { _available = _available * 2; } } function sellToAmmQuote( RangedMarket rangedMarket, RangedMarket.Position position, uint amount ) public view knownRangedMarket(address(rangedMarket)) returns (uint pricePaid) { (pricePaid, , ) = sellToAmmQuoteDetailed(rangedMarket, position, amount); } function sellToAmmQuoteDetailed( RangedMarket rangedMarket, RangedMarket.Position position, uint amount ) public view knownRangedMarket(address(rangedMarket)) returns ( uint quoteWithFees, uint leftQuote, uint rightQuote ) { amount = position == RangedMarket.Position.Out ? amount : amount / 2; leftQuote = thalesAmm.sellToAmmQuote( address(rangedMarket.leftMarket()), position == RangedMarket.Position.Out ? IThalesAMM.Position.Down : IThalesAMM.Position.Up, amount ); rightQuote = thalesAmm.sellToAmmQuote( address(rangedMarket.rightMarket()), position == RangedMarket.Position.Out ? IThalesAMM.Position.Up : IThalesAMM.Position.Down, amount ); quoteWithFees = _sellToAmmQuoteDetailedWithLeftAndRightQuotes(position, amount, leftQuote, rightQuote); } function sellToAMM( RangedMarket rangedMarket, RangedMarket.Position position, uint amount, uint expectedPayout, uint additionalSlippage ) public knownRangedMarket(address(rangedMarket)) nonReentrant notPaused { uint pricePaid; _handleApprovals(rangedMarket); if (position == RangedMarket.Position.Out) { rangedMarket.burnOut(amount, msg.sender); } else { rangedMarket.burnIn(amount, msg.sender); } pricePaid = _handleSellToAmm(rangedMarket, position, amount); require(pricePaid > 0 && (expectedPayout * ONE) / pricePaid <= (ONE + additionalSlippage), "ID2"); if (position == RangedMarket.Position.In) { _handleSafeBoxFeeOnSell(amount, rangedMarket, pricePaid); } sUSD.safeTransfer(msg.sender, pricePaid); _handleReferrer(msg.sender, pricePaid); if (address(stakingThales) != address(0)) { stakingThales.updateVolume(msg.sender, pricePaid); } (RangedPosition inp, RangedPosition outp) = rangedMarket.positions(); address target = position == RangedMarket.Position.Out ? address(outp) : address(inp); emit SoldToAMM(msg.sender, address(rangedMarket), position, amount, pricePaid, address(sUSD), target); } /// @notice resolveRangedMarketsBatch resolve all markets in the batch /// @param markets the batch function resolveRangedMarketsBatch(address[] calldata markets) external { for (uint i = 0; i < markets.length; i++) { address market = markets[i]; if (_knownMarkets.contains(market) && !RangedMarket(market).resolved()) { RangedMarket(market).resolveMarket(); } } } function getPriceImpact(RangedMarket rangedMarket, RangedMarket.Position position) external view returns (int _impact) { int buyPriceImpactLeft = thalesAmm.buyPriceImpact( address(rangedMarket.leftMarket()), position == RangedMarket.Position.Out ? IThalesAMM.Position.Down : IThalesAMM.Position.Up, ONE ); int buyPriceImpactRight = thalesAmm.buyPriceImpact( address(rangedMarket.rightMarket()), position == RangedMarket.Position.Out ? IThalesAMM.Position.Up : IThalesAMM.Position.Down, ONE ); _impact = buyPriceImpactLeft + buyPriceImpactRight; if (position == RangedMarket.Position.Out) { _impact = _impact / 2; } } function _sellToAmmQuoteDetailedWithLeftAndRightQuotes( RangedMarket.Position position, uint amount, uint leftQuote, uint rightQuote ) internal view returns (uint quoteWithFees) { if (leftQuote > 0 && rightQuote > 0) { uint summedQuotes = leftQuote + rightQuote; if (position == RangedMarket.Position.Out) { quoteWithFees = (summedQuotes * (ONE - rangedAmmFee)) / ONE; } else { uint amountTransformed = _transformCollateral(amount, false); if ( amountTransformed > leftQuote && amountTransformed > rightQuote && summedQuotes > ((amountTransformed - leftQuote) + (amountTransformed - rightQuote)) ) { uint quoteWithoutFees = summedQuotes - ((amountTransformed - leftQuote) + (amountTransformed - rightQuote)); quoteWithFees = (quoteWithoutFees * (ONE - rangedAmmFee - safeBoxImpact)) / ONE; } } } } function _handleSellToAmm( RangedMarket rangedMarket, RangedMarket.Position position, uint amount ) internal returns (uint) { uint baseAMMAmount = position == RangedMarket.Position.Out ? amount : amount / 2; uint sellLeft = thalesAmm.sellToAMM( address(rangedMarket.leftMarket()), position == RangedMarket.Position.Out ? IThalesAMM.Position.Down : IThalesAMM.Position.Up, baseAMMAmount, 0, 0 ); uint sellRight = thalesAmm.sellToAMM( address(rangedMarket.rightMarket()), position == RangedMarket.Position.Out ? IThalesAMM.Position.Up : IThalesAMM.Position.Down, baseAMMAmount, 0, 0 ); return _sellToAmmQuoteDetailedWithLeftAndRightQuotes(position, baseAMMAmount, sellLeft, sellRight); } function _handleApprovals(RangedMarket rangedMarket) internal { (IPosition up, IPosition down) = IPositionalMarket(rangedMarket.leftMarket()).getOptions(); (IPosition up1, IPosition down1) = IPositionalMarket(rangedMarket.rightMarket()).getOptions(); IERC20Upgradeable(address(up)).approve(address(thalesAmm), type(uint256).max); IERC20Upgradeable(address(down)).approve(address(thalesAmm), type(uint256).max); IERC20Upgradeable(address(up1)).approve(address(thalesAmm), type(uint256).max); IERC20Upgradeable(address(down1)).approve(address(thalesAmm), type(uint256).max); } function _handleReferrer(address buyer, uint sUSDPaid) internal { if (referrerFee > 0 && referrals != address(0)) { address referrer = IReferrals(referrals).referrals(buyer); if (referrer != address(0)) { uint referrerShare = (sUSDPaid * (ONE + referrerFee)) / ONE - sUSDPaid; sUSD.transfer(referrer, referrerShare); emit ReferrerPaid(referrer, buyer, referrerShare, sUSDPaid); } } } function _mapCollateralToCurveIndex(address collateral) internal view returns (int128) { if (collateral == dai) { return 1; } if (collateral == usdc) { return 2; } if (collateral == usdt) { return 3; } return 0; } function _handleSafeBoxFeeOnBuy( address rangedMarket, uint amount, uint sUSDPaid ) internal { uint safeBoxShare; if (safeBoxImpact > 0) { safeBoxShare = sUSDPaid - ((sUSDPaid * ONE) / (ONE + safeBoxImpact)); sUSD.transfer(safeBox, safeBoxShare); } } function _handleSafeBoxFeeOnSell( uint amount, RangedMarket rangedMarket, uint sUSDPaid ) internal { uint safeBoxShare = 0; if (safeBoxImpact > 0) { safeBoxShare = ((sUSDPaid * ONE) / (ONE - safeBoxImpact)) - sUSDPaid; sUSD.transfer(safeBox, safeBoxShare); } } function _createRangedMarket(address leftMarket, address rightMarket) internal { require(canCreateRangedMarket(leftMarket, rightMarket), "Can't create such a ranged market!"); RangedMarket rm = RangedMarket(Clones.clone(rangedMarketMastercopy)); createdRangedMarkets[leftMarket][rightMarket] = address(rm); RangedPosition inp = RangedPosition(Clones.clone(rangedPositionMastercopy)); inp.initialize(address(rm), "Position IN", "IN", address(this)); RangedPosition outp = RangedPosition(Clones.clone(rangedPositionMastercopy)); outp.initialize(address(rm), "Position OUT", "OUT", address(this)); rm.initialize(leftMarket, rightMarket, address(inp), address(outp), address(this)); _knownMarkets.add(address(rm)); emit RangedMarketCreated(address(rm), leftMarket, rightMarket); } function _transformCollateral(uint collateral, bool reverse) internal view returns (uint transformed) { transformed = reverse ? IPositionalMarketManager(thalesAmm.manager()).reverseTransformCollateral(collateral) : IPositionalMarketManager(thalesAmm.manager()).transformCollateral(collateral); } function transferSusdTo(address receiver, uint amount) external { require(_knownMarkets.contains(msg.sender), "Not a known ranged market"); sUSD.safeTransfer(receiver, amount); } function retrieveSUSDAmount(address payable account, uint amount) external onlyOwner { sUSD.safeTransfer(account, amount); } function setRangedMarketMastercopies(address _rangedMarketMastercopy, address _rangedPositionMastercopy) external onlyOwner { rangedMarketMastercopy = _rangedMarketMastercopy; rangedPositionMastercopy = _rangedPositionMastercopy; } function setMinMaxSupportedPrice( uint _minSupportedPrice, uint _maxSupportedPrice, uint _minDiffBetweenStrikes, uint _maxDiffBetweenStrikes ) public onlyOwner { minSupportedPrice = _minSupportedPrice; maxSupportedPrice = _maxSupportedPrice; minimalDifBetweenStrikes = _minDiffBetweenStrikes; maximalDifBetweenStrikes = _maxDiffBetweenStrikes; emit SetMinMaxSupportedPrice(minSupportedPrice, maxSupportedPrice); emit SetMinimalMaximalDifBetweenStrikes(minimalDifBetweenStrikes, maximalDifBetweenStrikes); } function setSafeBoxDataAndRangedAMMFee( address _safeBox, uint _safeBoxImpact, uint _rangedAMMFee ) external onlyOwner { safeBoxImpact = _safeBoxImpact; safeBox = _safeBox; emit SafeBoxChanged(_safeBoxImpact, _safeBox); rangedAmmFee = _rangedAMMFee; emit SetRangedFee(rangedAmmFee); } function setThalesAMMStakingThalesAndReferrals( address _thalesAMM, IStakingThales _stakingThales, address _referrals, uint _referrerFee ) external onlyOwner { thalesAmm = IThalesAMM(_thalesAMM); sUSD.approve(address(thalesAmm), type(uint256).max); stakingThales = _stakingThales; referrals = _referrals; referrerFee = _referrerFee; } /// @notice Updates contract parametars /// @param _curveOnrampEnabled whether AMM supports curve onramp /// @param _maxAllowedPegSlippagePercentage maximum discount AMM accepts for sUSD purchases function setCurveSUSD(bool _curveOnrampEnabled, uint _maxAllowedPegSlippagePercentage) external onlyOwner { curveOnrampEnabled = _curveOnrampEnabled; maxAllowedPegSlippagePercentage = _maxAllowedPegSlippagePercentage; } modifier knownRangedMarket(address market) { require(_knownMarkets.contains(market), "Not a known ranged market"); _; } event SoldToAMM( address seller, address market, RangedMarket.Position position, uint amount, uint sUSDPaid, address susd, address asset ); event BoughtFromAmm( address buyer, address market, RangedMarket.Position position, uint amount, uint sUSDPaid, address susd, address asset ); event BoughtOptionType(address buyer, uint sUSDPaid, bool inTheMoney); event RangedMarketCreated(address market, address leftMarket, address rightMarket); event SafeBoxChanged(uint _safeBoxImpact, address _safeBox); event SetMinMaxSupportedPrice(uint minSupportedPrice, uint maxSupportedPrice); event SetMinimalMaximalDifBetweenStrikes(uint minSupportedPrice, uint maxSupportedPrice); event SetRangedFee(uint rangedAmmFee); event ReferrerPaid(address refferer, address trader, uint amount, uint volume); }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; import "./IPriceFeed.sol"; interface IThalesAMM { enum Position { Up, Down } function manager() external view returns (address); function availableToBuyFromAMM(address market, Position position) external view returns (uint); function impliedVolatilityPerAsset(bytes32 oracleKey) external view returns (uint); function buyFromAmmQuote( address market, Position position, uint amount ) external view returns (uint); function buyFromAMM( address market, Position position, uint amount, uint expectedPayout, uint additionalSlippage ) external returns (uint); function availableToSellToAMM(address market, Position position) external view returns (uint); function sellToAmmQuote( address market, Position position, uint amount ) external view returns (uint); function sellToAMM( address market, Position position, uint amount, uint expectedPayout, uint additionalSlippage ) external returns (uint); function isMarketInAMMTrading(address market) external view returns (bool); function price(address market, Position position) external view returns (uint); function buyPriceImpact( address market, Position position, uint amount ) external view returns (int); function sellPriceImpact( address market, Position position, uint amount ) external view returns (int); function priceFeed() external view returns (IPriceFeed); }
// 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 // OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; import "./IPositionalMarket.sol"; interface IPosition { /* ========== VIEWS / VARIABLES ========== */ function getBalanceOf(address account) external view returns (uint); function getTotalSupply() external view returns (uint); function exerciseWithAmount(address claimant, uint amount) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol) pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the subtraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; import "../interfaces/IPositionalMarketManager.sol"; import "../interfaces/IPosition.sol"; import "../interfaces/IPriceFeed.sol"; interface IPositionalMarket { /* ========== TYPES ========== */ enum Phase { Trading, Maturity, Expiry } enum Side { Up, Down } /* ========== VIEWS / VARIABLES ========== */ function getOptions() external view returns (IPosition up, IPosition down); function times() external view returns (uint maturity, uint destructino); function getOracleDetails() external view returns ( bytes32 key, uint strikePrice, uint finalPrice ); function fees() external view returns (uint poolFee, uint creatorFee); function deposited() external view returns (uint); function creator() external view returns (address); function resolved() external view returns (bool); function phase() external view returns (Phase); function oraclePrice() external view returns (uint); function oraclePriceAndTimestamp() external view returns (uint price, uint updatedAt); function canResolve() external view returns (bool); function result() external view returns (Side); function balancesOf(address account) external view returns (uint up, uint down); function totalSupplies() external view returns (uint up, uint down); function getMaximumBurnable(address account) external view returns (uint amount); /* ========== MUTATIVE FUNCTIONS ========== */ function mint(uint value) external; function exerciseOptions() external returns (uint); function burnOptions(uint amount) external; function burnOptionsMaximum() external; }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; import "../interfaces/IPositionalMarket.sol"; interface IPositionalMarketManager { /* ========== VIEWS / VARIABLES ========== */ function durations() external view returns (uint expiryDuration, uint maxTimeToMaturity); function capitalRequirement() external view returns (uint); function marketCreationEnabled() external view returns (bool); function onlyAMMMintingAndBurning() external view returns (bool); function transformCollateral(uint value) external view returns (uint); function reverseTransformCollateral(uint value) external view returns (uint); function totalDeposited() external view returns (uint); function numActiveMarkets() external view returns (uint); function activeMarkets(uint index, uint pageSize) external view returns (address[] memory); function numMaturedMarkets() external view returns (uint); function maturedMarkets(uint index, uint pageSize) external view returns (address[] memory); function isActiveMarket(address candidate) external view returns (bool); function isKnownMarket(address candidate) external view returns (bool); function getThalesAMM() external view returns (address); /* ========== MUTATIVE FUNCTIONS ========== */ function createMarket( bytes32 oracleKey, uint strikePrice, uint maturity, uint initialMint // initial sUSD to mint options for, ) external returns (IPositionalMarket); function resolveMarket(address market) external; function expireMarkets(address[] calldata market) external; function transferSusdTo( address sender, address receiver, uint amount ) external; }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; interface IPriceFeed { // Structs struct RateAndUpdatedTime { uint216 rate; uint40 time; } // Mutative functions function addAggregator(bytes32 currencyKey, address aggregatorAddress) external; function removeAggregator(bytes32 currencyKey) external; // Views function rateForCurrency(bytes32 currencyKey) external view returns (uint); function rateAndUpdatedTime(bytes32 currencyKey) external view returns (uint rate, uint time); function getRates() external view returns (uint[] memory); function getCurrencies() external view returns (bytes32[] memory); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract OwnedWithInit { address public owner; address public nominatedOwner; constructor() {} function initOwner(address _owner) internal { require(owner == address(0), "Init can only be called when owner is 0"); owner = _owner; emit OwnerChanged(address(0), _owner); } function nominateNewOwner(address _owner) external onlyOwner { nominatedOwner = _owner; emit OwnerNominated(_owner); } function acceptOwnership() external { require(msg.sender == nominatedOwner, "You must be nominated before you can accept ownership"); emit OwnerChanged(owner, nominatedOwner); owner = nominatedOwner; nominatedOwner = address(0); } modifier onlyOwner { _onlyOwner(); _; } function _onlyOwner() private view { require(msg.sender == owner, "Only the contract owner may perform this action"); } event OwnerNominated(address newOwner); event OwnerChanged(address oldOwner, address newOwner); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../interfaces/IPositionalMarket.sol"; interface IOracleInstance { /* ========== VIEWS / VARIABLES ========== */ function getOutcome() external view returns (bool); function resolvable() external view returns (bool); }
// 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.8.0; // ---------------------------------------------------------------------------- // DateTime Library v2.0 // // A gas-efficient Solidity date and time library // // https://github.com/bokkypoobah/BokkyPooBahsDateTimeLibrary // // Tested date range 1970/01/01 to 2345/12/31 // // Conventions: // Unit | Range | Notes // :-------- |:-------------:|:----- // timestamp | >= 0 | Unix timestamp, number of seconds since 1970/01/01 00:00:00 UTC // year | 1970 ... 2345 | // month | 1 ... 12 | // day | 1 ... 31 | // hour | 0 ... 23 | // minute | 0 ... 59 | // second | 0 ... 59 | // dayOfWeek | 1 ... 7 | 1 = Monday, ..., 7 = Sunday // // // Enjoy. (c) BokkyPooBah / Bok Consulting Pty Ltd 2018-2019. The MIT Licence. // ---------------------------------------------------------------------------- library DateTime { uint256 constant SECONDS_PER_DAY = 24 * 60 * 60; uint256 constant SECONDS_PER_HOUR = 60 * 60; uint256 constant SECONDS_PER_MINUTE = 60; int256 constant OFFSET19700101 = 2440588; uint256 constant DOW_MON = 1; uint256 constant DOW_TUE = 2; uint256 constant DOW_WED = 3; uint256 constant DOW_THU = 4; uint256 constant DOW_FRI = 5; uint256 constant DOW_SAT = 6; uint256 constant DOW_SUN = 7; // ------------------------------------------------------------------------ // Calculate the number of days from 1970/01/01 to year/month/day using // the date conversion algorithm from // http://aa.usno.navy.mil/faq/docs/JD_Formula.php // and subtracting the offset 2440588 so that 1970/01/01 is day 0 // // days = day // - 32075 // + 1461 * (year + 4800 + (month - 14) / 12) / 4 // + 367 * (month - 2 - (month - 14) / 12 * 12) / 12 // - 3 * ((year + 4900 + (month - 14) / 12) / 100) / 4 // - offset // ------------------------------------------------------------------------ function _daysFromDate( uint256 year, uint256 month, uint256 day ) internal pure returns (uint256 _days) { require(year >= 1970); int256 _year = int256(year); int256 _month = int256(month); int256 _day = int256(day); int256 __days = _day - 32075 + (1461 * (_year + 4800 + (_month - 14) / 12)) / 4 + (367 * (_month - 2 - ((_month - 14) / 12) * 12)) / 12 - (3 * ((_year + 4900 + (_month - 14) / 12) / 100)) / 4 - OFFSET19700101; _days = uint256(__days); } // ------------------------------------------------------------------------ // Calculate year/month/day from the number of days since 1970/01/01 using // the date conversion algorithm from // http://aa.usno.navy.mil/faq/docs/JD_Formula.php // and adding the offset 2440588 so that 1970/01/01 is day 0 // // int L = days + 68569 + offset // int N = 4 * L / 146097 // L = L - (146097 * N + 3) / 4 // year = 4000 * (L + 1) / 1461001 // L = L - 1461 * year / 4 + 31 // month = 80 * L / 2447 // dd = L - 2447 * month / 80 // L = month / 11 // month = month + 2 - 12 * L // year = 100 * (N - 49) + year + L // ------------------------------------------------------------------------ function _daysToDate(uint256 _days) internal pure returns ( uint256 year, uint256 month, uint256 day ) { int256 __days = int256(_days); int256 L = __days + 68569 + OFFSET19700101; int256 N = (4 * L) / 146097; L = L - (146097 * N + 3) / 4; int256 _year = (4000 * (L + 1)) / 1461001; L = L - (1461 * _year) / 4 + 31; int256 _month = (80 * L) / 2447; int256 _day = L - (2447 * _month) / 80; L = _month / 11; _month = _month + 2 - 12 * L; _year = 100 * (N - 49) + _year + L; year = uint256(_year); month = uint256(_month); day = uint256(_day); } function timestampFromDate( uint256 year, uint256 month, uint256 day ) internal pure returns (uint256 timestamp) { timestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY; } function timestampFromDateTime( uint256 year, uint256 month, uint256 day, uint256 hour, uint256 minute, uint256 second ) internal pure returns (uint256 timestamp) { timestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY + hour * SECONDS_PER_HOUR + minute * SECONDS_PER_MINUTE + second; } function timestampToDate(uint256 timestamp) internal pure returns ( uint256 year, uint256 month, uint256 day ) { (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY); } function timestampToDateTime(uint256 timestamp) internal pure returns ( uint256 year, uint256 month, uint256 day, uint256 hour, uint256 minute, uint256 second ) { (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY); uint256 secs = timestamp % SECONDS_PER_DAY; hour = secs / SECONDS_PER_HOUR; secs = secs % SECONDS_PER_HOUR; minute = secs / SECONDS_PER_MINUTE; second = secs % SECONDS_PER_MINUTE; } function isValidDate( uint256 year, uint256 month, uint256 day ) internal pure returns (bool valid) { if (year >= 1970 && month > 0 && month <= 12) { uint256 daysInMonth = _getDaysInMonth(year, month); if (day > 0 && day <= daysInMonth) { valid = true; } } } function isValidDateTime( uint256 year, uint256 month, uint256 day, uint256 hour, uint256 minute, uint256 second ) internal pure returns (bool valid) { if (isValidDate(year, month, day)) { if (hour < 24 && minute < 60 && second < 60) { valid = true; } } } function isLeapYear(uint256 timestamp) internal pure returns (bool leapYear) { (uint256 year, , ) = _daysToDate(timestamp / SECONDS_PER_DAY); leapYear = _isLeapYear(year); } function _isLeapYear(uint256 year) internal pure returns (bool leapYear) { leapYear = ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0); } function isWeekDay(uint256 timestamp) internal pure returns (bool weekDay) { weekDay = getDayOfWeek(timestamp) <= DOW_FRI; } function isWeekEnd(uint256 timestamp) internal pure returns (bool weekEnd) { weekEnd = getDayOfWeek(timestamp) >= DOW_SAT; } function getDaysInMonth(uint256 timestamp) internal pure returns (uint256 daysInMonth) { (uint256 year, uint256 month, ) = _daysToDate(timestamp / SECONDS_PER_DAY); daysInMonth = _getDaysInMonth(year, month); } function _getDaysInMonth(uint256 year, uint256 month) internal pure returns (uint256 daysInMonth) { if ( month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 ) { daysInMonth = 31; } else if (month != 2) { daysInMonth = 30; } else { daysInMonth = _isLeapYear(year) ? 29 : 28; } } // 1 = Monday, 7 = Sunday function getDayOfWeek(uint256 timestamp) internal pure returns (uint256 dayOfWeek) { uint256 _days = timestamp / SECONDS_PER_DAY; dayOfWeek = ((_days + 3) % 7) + 1; } function getYear(uint256 timestamp) internal pure returns (uint256 year) { (year, , ) = _daysToDate(timestamp / SECONDS_PER_DAY); } function getMonth(uint256 timestamp) internal pure returns (uint256 month) { (, month, ) = _daysToDate(timestamp / SECONDS_PER_DAY); } function getDay(uint256 timestamp) internal pure returns (uint256 day) { (, , day) = _daysToDate(timestamp / SECONDS_PER_DAY); } function getHour(uint256 timestamp) internal pure returns (uint256 hour) { uint256 secs = timestamp % SECONDS_PER_DAY; hour = secs / SECONDS_PER_HOUR; } function getMinute(uint256 timestamp) internal pure returns (uint256 minute) { uint256 secs = timestamp % SECONDS_PER_HOUR; minute = secs / SECONDS_PER_MINUTE; } function getSecond(uint256 timestamp) internal pure returns (uint256 second) { second = timestamp % SECONDS_PER_MINUTE; } function addYears(uint256 timestamp, uint256 _years) internal pure returns (uint256 newTimestamp) { (uint256 year, uint256 month, uint256 day) = _daysToDate(timestamp / SECONDS_PER_DAY); year += _years; uint256 daysInMonth = _getDaysInMonth(year, month); if (day > daysInMonth) { day = daysInMonth; } newTimestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY + (timestamp % SECONDS_PER_DAY); require(newTimestamp >= timestamp); } function addMonths(uint256 timestamp, uint256 _months) internal pure returns (uint256 newTimestamp) { (uint256 year, uint256 month, uint256 day) = _daysToDate(timestamp / SECONDS_PER_DAY); month += _months; year += (month - 1) / 12; month = ((month - 1) % 12) + 1; uint256 daysInMonth = _getDaysInMonth(year, month); if (day > daysInMonth) { day = daysInMonth; } newTimestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY + (timestamp % SECONDS_PER_DAY); require(newTimestamp >= timestamp); } function addDays(uint256 timestamp, uint256 _days) internal pure returns (uint256 newTimestamp) { newTimestamp = timestamp + _days * SECONDS_PER_DAY; require(newTimestamp >= timestamp); } function addHours(uint256 timestamp, uint256 _hours) internal pure returns (uint256 newTimestamp) { newTimestamp = timestamp + _hours * SECONDS_PER_HOUR; require(newTimestamp >= timestamp); } function addMinutes(uint256 timestamp, uint256 _minutes) internal pure returns (uint256 newTimestamp) { newTimestamp = timestamp + _minutes * SECONDS_PER_MINUTE; require(newTimestamp >= timestamp); } function addSeconds(uint256 timestamp, uint256 _seconds) internal pure returns (uint256 newTimestamp) { newTimestamp = timestamp + _seconds; require(newTimestamp >= timestamp); } function subYears(uint256 timestamp, uint256 _years) internal pure returns (uint256 newTimestamp) { (uint256 year, uint256 month, uint256 day) = _daysToDate(timestamp / SECONDS_PER_DAY); year -= _years; uint256 daysInMonth = _getDaysInMonth(year, month); if (day > daysInMonth) { day = daysInMonth; } newTimestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY + (timestamp % SECONDS_PER_DAY); require(newTimestamp <= timestamp); } function subMonths(uint256 timestamp, uint256 _months) internal pure returns (uint256 newTimestamp) { (uint256 year, uint256 month, uint256 day) = _daysToDate(timestamp / SECONDS_PER_DAY); uint256 yearMonth = year * 12 + (month - 1) - _months; year = yearMonth / 12; month = (yearMonth % 12) + 1; uint256 daysInMonth = _getDaysInMonth(year, month); if (day > daysInMonth) { day = daysInMonth; } newTimestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY + (timestamp % SECONDS_PER_DAY); require(newTimestamp <= timestamp); } function subDays(uint256 timestamp, uint256 _days) internal pure returns (uint256 newTimestamp) { newTimestamp = timestamp - _days * SECONDS_PER_DAY; require(newTimestamp <= timestamp); } function subHours(uint256 timestamp, uint256 _hours) internal pure returns (uint256 newTimestamp) { newTimestamp = timestamp - _hours * SECONDS_PER_HOUR; require(newTimestamp <= timestamp); } function subMinutes(uint256 timestamp, uint256 _minutes) internal pure returns (uint256 newTimestamp) { newTimestamp = timestamp - _minutes * SECONDS_PER_MINUTE; require(newTimestamp <= timestamp); } function subSeconds(uint256 timestamp, uint256 _seconds) internal pure returns (uint256 newTimestamp) { newTimestamp = timestamp - _seconds; require(newTimestamp <= timestamp); } function diffYears(uint256 fromTimestamp, uint256 toTimestamp) internal pure returns (uint256 _years) { require(fromTimestamp <= toTimestamp); (uint256 fromYear, , ) = _daysToDate(fromTimestamp / SECONDS_PER_DAY); (uint256 toYear, , ) = _daysToDate(toTimestamp / SECONDS_PER_DAY); _years = toYear - fromYear; } function diffMonths(uint256 fromTimestamp, uint256 toTimestamp) internal pure returns (uint256 _months) { require(fromTimestamp <= toTimestamp); (uint256 fromYear, uint256 fromMonth, ) = _daysToDate(fromTimestamp / SECONDS_PER_DAY); (uint256 toYear, uint256 toMonth, ) = _daysToDate(toTimestamp / SECONDS_PER_DAY); _months = toYear * 12 + toMonth - fromYear * 12 - fromMonth; } function diffDays(uint256 fromTimestamp, uint256 toTimestamp) internal pure returns (uint256 _days) { require(fromTimestamp <= toTimestamp); _days = (toTimestamp - fromTimestamp) / SECONDS_PER_DAY; } function diffHours(uint256 fromTimestamp, uint256 toTimestamp) internal pure returns (uint256 _hours) { require(fromTimestamp <= toTimestamp); _hours = (toTimestamp - fromTimestamp) / SECONDS_PER_HOUR; } function diffMinutes(uint256 fromTimestamp, uint256 toTimestamp) internal pure returns (uint256 _minutes) { require(fromTimestamp <= toTimestamp); _minutes = (toTimestamp - fromTimestamp) / SECONDS_PER_MINUTE; } function diffSeconds(uint256 fromTimestamp, uint256 toTimestamp) internal pure returns (uint256 _seconds) { require(fromTimestamp <= toTimestamp); _seconds = toTimestamp - fromTimestamp; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // Inheritance import "../utils/proxy/solidity-0.8.0/ProxyOwned.sol"; // Internal references import "./Position.sol"; import "./PositionalMarket.sol"; import "./PositionalMarketFactory.sol"; import "../interfaces/IPriceFeed.sol"; import "../interfaces/IPositionalMarket.sol"; import "@openzeppelin/contracts-4.4.1/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts-4.4.1/proxy/Clones.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; contract PositionalMarketFactory is Initializable, ProxyOwned { /* ========== STATE VARIABLES ========== */ address public positionalMarketManager; address public positionalMarketMastercopy; address public positionMastercopy; address public limitOrderProvider; address public thalesAMM; struct PositionCreationMarketParameters { address creator; IERC20 _sUSD; IPriceFeed _priceFeed; bytes32 oracleKey; uint strikePrice; uint[2] times; // [maturity, expiry] uint initialMint; } function initialize(address _owner) external initializer { setOwner(_owner); } /// @notice createMarket create market function /// @param _parameters PositionCreationMarketParameters needed for market creation /// @return PositionalMarket created market function createMarket(PositionCreationMarketParameters calldata _parameters) external returns (PositionalMarket) { require(positionalMarketManager == msg.sender, "Only permitted by the manager."); PositionalMarket pom = PositionalMarket(Clones.clone(positionalMarketMastercopy)); Position up = Position(Clones.clone(positionMastercopy)); Position down = Position(Clones.clone(positionMastercopy)); pom.initialize( PositionalMarket.PositionalMarketParameters( positionalMarketManager, _parameters._sUSD, _parameters._priceFeed, _parameters.creator, _parameters.oracleKey, _parameters.strikePrice, _parameters.times, _parameters.initialMint, address(up), address(down), thalesAMM ) ); emit MarketCreated( address(pom), _parameters.oracleKey, _parameters.strikePrice, _parameters.times[0], _parameters.times[1], _parameters.initialMint ); return pom; } /// @notice setPositionalMarketManager sets positionalMarketManager value /// @param _positionalMarketManager address of the PositionalMarketManager contract function setPositionalMarketManager(address _positionalMarketManager) external onlyOwner { positionalMarketManager = _positionalMarketManager; emit PositionalMarketManagerChanged(_positionalMarketManager); } /// @notice setPositionalMarketMastercopy sets positionalMarketMastercopy value /// @param _positionalMarketMastercopy address of the PositionalMarketMastercopy contract function setPositionalMarketMastercopy(address _positionalMarketMastercopy) external onlyOwner { positionalMarketMastercopy = _positionalMarketMastercopy; emit PositionalMarketMastercopyChanged(_positionalMarketMastercopy); } /// @notice setPositionMastercopy sets positionMastercopy value /// @param _positionMastercopy address of the PositionMastercopy contract function setPositionMastercopy(address _positionMastercopy) external onlyOwner { positionMastercopy = _positionMastercopy; emit PositionMastercopyChanged(_positionMastercopy); } /// @notice setThalesAMM sets thalesAMM value /// @param _thalesAMM address of ThalesAMM contract function setThalesAMM(address _thalesAMM) external onlyOwner { thalesAMM = _thalesAMM; emit SetThalesAMM(_thalesAMM); } event PositionalMarketManagerChanged(address _positionalMarketManager); event PositionalMarketMastercopyChanged(address _positionalMarketMastercopy); event PositionMastercopyChanged(address _positionMastercopy); event SetThalesAMM(address _thalesAMM); event MarketCreated( address market, bytes32 indexed oracleKey, uint strikePrice, uint maturityDate, uint expiryDate, uint initialMint ); }
// 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 // OpenZeppelin Contracts v4.4.1 (utils/Address.sol) pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/draft-IERC20Permit.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// in position collaterized by 0.5 UP on the left leg and 0.5 DOWN on the right leg // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // Inheritance import "@openzeppelin/contracts-4.4.1/token/ERC20/IERC20.sol"; import "../interfaces/IPosition.sol"; // Internal references import "./RangedMarket.sol"; contract RangedPosition is IERC20 { /* ========== STATE VARIABLES ========== */ string public name; string public symbol; uint8 public constant decimals = 18; RangedMarket public rangedMarket; mapping(address => uint) public override balanceOf; uint public override totalSupply; // The argument order is allowance[owner][spender] mapping(address => mapping(address => uint)) private allowances; // Enforce a 1 cent minimum amount uint internal constant _MINIMUM_AMOUNT = 1e16; address public thalesRangedAMM; /* ========== CONSTRUCTOR ========== */ bool public initialized = false; function initialize( address market, string calldata _name, string calldata _symbol, address _thalesRangedAMM ) external { require(!initialized, "Ranged Market already initialized"); initialized = true; rangedMarket = RangedMarket(market); name = _name; symbol = _symbol; thalesRangedAMM = _thalesRangedAMM; } function allowance(address owner, address spender) external view override returns (uint256) { if (spender == thalesRangedAMM) { return type(uint256).max; } else { return allowances[owner][spender]; } } function burn(address claimant, uint amount) external onlyRangedMarket { balanceOf[claimant] = balanceOf[claimant] - amount; totalSupply = totalSupply - amount; emit Burned(claimant, amount); emit Transfer(claimant, address(0), amount); } function mint(address minter, uint amount) external onlyRangedMarket { _requireMinimumAmount(amount); totalSupply = totalSupply + amount; balanceOf[minter] = balanceOf[minter] + amount; // Increment rather than assigning since a transfer may have occurred. emit Mint(minter, amount); emit Transfer(address(0), minter, amount); } /* ---------- ERC20 Functions ---------- */ function _transfer( address _from, address _to, uint _value ) internal returns (bool success) { require(_to != address(0) && _to != address(this), "Invalid address"); uint fromBalance = balanceOf[_from]; require(_value <= fromBalance, "Insufficient balance"); balanceOf[_from] = fromBalance - _value; balanceOf[_to] = balanceOf[_to] + _value; emit Transfer(_from, _to, _value); return true; } function transfer(address _to, uint _value) external override returns (bool success) { return _transfer(msg.sender, _to, _value); } function transferFrom( address _from, address _to, uint _value ) external override returns (bool success) { if (msg.sender != thalesRangedAMM) { uint fromAllowance = allowances[_from][msg.sender]; require(_value <= fromAllowance, "Insufficient allowance"); allowances[_from][msg.sender] = fromAllowance - _value; } return _transfer(_from, _to, _value); } function approve(address _spender, uint _value) external override returns (bool success) { require(_spender != address(0)); allowances[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } function getBalanceOf(address account) external view returns (uint) { return balanceOf[account]; } function getTotalSupply() external view returns (uint) { return totalSupply; } modifier onlyRangedMarket { require(msg.sender == address(rangedMarket), "only the Ranged Market may perform these methods"); _; } function _requireMinimumAmount(uint amount) internal pure returns (uint) { require(amount >= _MINIMUM_AMOUNT || amount == 0, "Balance < $0.01"); return amount; } event Mint(address minter, uint amount); event Burned(address burner, uint amount); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// 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 (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20Upgradeable { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract PausableUpgradeable is Initializable, ContextUpgradeable { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ function __Pausable_init() internal onlyInitializing { __Context_init_unchained(); __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } uint256[49] private __gap; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the `nonReentrant` modifier * available, which can be aplied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. */ contract ProxyReentrancyGuard { /// @dev counter to allow mutex lock with only one SSTORE operation uint256 private _guardCounter; bool private _initialized; function initNonReentrant() public { require(!_initialized, "Already initialized"); _initialized = true; _guardCounter = 1; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and make it call a * `private` function that does the actual work. */ modifier nonReentrant() { _guardCounter += 1; uint256 localCounter = _guardCounter; _; require(localCounter == _guardCounter, "ReentrancyGuard: reentrant call"); } }
// SPDX-License-Identifier: MIT pragma solidity >=0.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 decreaseAndTransferStakedThales(address account, uint amount) external; function increaseAndTransferStakedThales(address account, uint amount) external; function updateVolumeAtAmountDecimals( address account, uint amount, uint decimals ) external; }
// 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.5.16; interface ICurveSUSD { function exchange_underlying( int128 i, int128 j, uint256 _dx, uint256 _min_dy ) external returns (uint256); function get_dy_underlying( int128 i, int128 j, uint256 _dx ) external view returns (uint256); // @notice Perform an exchange between two underlying coins // @param i Index value for the underlying coin to send // @param j Index valie of the underlying coin to receive // @param _dx Amount of `i` being exchanged // @param _min_dy Minimum amount of `j` to receive // @param _receiver Address that receives `j` // @return Actual amount of `j` received // indexes: // 0 = sUSD 18 dec 0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9 // 1= DAI 18 dec 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1 // 2= USDC 6 dec 0x7F5c764cBc14f9669B88837ca1490cCa17c31607 // 3= USDT 6 dec 0x94b008aA00579c1307B0EF2c499aD98a8ce58e58 }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { __Context_init_unchained(); } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; }
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"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":"_manager","type":"address"}],"name":"PositionalMarketManagerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_rangedMarketsAMM","type":"address"}],"name":"SetRangedMarketsAMM","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_thalesAMM","type":"address"}],"name":"SetThalesAMM","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract PositionalMarket","name":"market","type":"address"},{"internalType":"address","name":"account","type":"address"}],"name":"getAccountMarketData","outputs":[{"components":[{"components":[{"internalType":"uint256","name":"up","type":"uint256"},{"internalType":"uint256","name":"down","type":"uint256"}],"internalType":"struct PositionalMarketData.OptionValues","name":"balances","type":"tuple"}],"internalType":"struct PositionalMarketData.AccountData","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"markets","type":"address[]"},{"internalType":"enum IThalesAMM.Position","name":"position","type":"uint8"}],"name":"getActiveMarketsInfoPerPosition","outputs":[{"components":[{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"int256","name":"priceImpact","type":"int256"},{"internalType":"uint256","name":"strikePrice","type":"uint256"}],"internalType":"struct PositionalMarketData.ActiveMarketsInfoPerPosition[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"market","type":"address"}],"name":"getAmmMarketData","outputs":[{"components":[{"internalType":"uint256","name":"upBuyLiquidity","type":"uint256"},{"internalType":"uint256","name":"downBuyLiquidity","type":"uint256"},{"internalType":"uint256","name":"upSellLiquidity","type":"uint256"},{"internalType":"uint256","name":"downSellLiquidity","type":"uint256"},{"internalType":"uint256","name":"upBuyPrice","type":"uint256"},{"internalType":"uint256","name":"downBuyPrice","type":"uint256"},{"internalType":"uint256","name":"upSellPrice","type":"uint256"},{"internalType":"uint256","name":"downSellPrice","type":"uint256"},{"internalType":"int256","name":"upBuyPriceImpact","type":"int256"},{"internalType":"int256","name":"downBuyPriceImpact","type":"int256"},{"internalType":"int256","name":"upSellPriceImpact","type":"int256"},{"internalType":"int256","name":"downSellPriceImpact","type":"int256"},{"internalType":"uint256","name":"iv","type":"uint256"},{"internalType":"bool","name":"isMarketInAMMTrading","type":"bool"}],"internalType":"struct PositionalMarketData.AmmMarketData","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAvailableAssets","outputs":[{"internalType":"bytes32[]","name":"","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"start","type":"uint256"},{"internalType":"uint256","name":"end","type":"uint256"}],"name":"getBatchBasePricesForAllActiveMarkets","outputs":[{"components":[{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"upPrice","type":"uint256"},{"internalType":"uint256","name":"downPrice","type":"uint256"}],"internalType":"struct PositionalMarketData.ActiveMarketsPrices[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"start","type":"uint256"},{"internalType":"uint256","name":"end","type":"uint256"}],"name":"getBatchPriceImpactForAllActiveMarkets","outputs":[{"components":[{"internalType":"address","name":"market","type":"address"},{"internalType":"int256","name":"upPriceImpact","type":"int256"},{"internalType":"int256","name":"downPriceImpact","type":"int256"}],"internalType":"struct PositionalMarketData.ActiveMarketsPriceImpact[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract PositionalMarket","name":"market","type":"address"}],"name":"getMarketData","outputs":[{"components":[{"components":[{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"}],"internalType":"struct PositionalMarketData.OraclePriceAndTimestamp","name":"oraclePriceAndTimestamp","type":"tuple"},{"components":[{"internalType":"uint256","name":"deposited","type":"uint256"}],"internalType":"struct PositionalMarketData.Deposits","name":"deposits","type":"tuple"},{"components":[{"internalType":"bool","name":"resolved","type":"bool"},{"internalType":"bool","name":"canResolve","type":"bool"}],"internalType":"struct PositionalMarketData.Resolution","name":"resolution","type":"tuple"},{"internalType":"enum IPositionalMarket.Phase","name":"phase","type":"uint8"},{"internalType":"enum IPositionalMarket.Side","name":"result","type":"uint8"},{"components":[{"internalType":"uint256","name":"up","type":"uint256"},{"internalType":"uint256","name":"down","type":"uint256"}],"internalType":"struct PositionalMarketData.OptionValues","name":"totalSupplies","type":"tuple"}],"internalType":"struct PositionalMarketData.MarketData","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract PositionalMarket","name":"market","type":"address"}],"name":"getMarketParameters","outputs":[{"components":[{"internalType":"address","name":"creator","type":"address"},{"components":[{"internalType":"contract Position","name":"up","type":"address"},{"internalType":"contract Position","name":"down","type":"address"}],"internalType":"struct PositionalMarket.Options","name":"options","type":"tuple"},{"components":[{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"}],"internalType":"struct PositionalMarket.Times","name":"times","type":"tuple"},{"components":[{"internalType":"bytes32","name":"key","type":"bytes32"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"uint256","name":"finalPrice","type":"uint256"},{"internalType":"bool","name":"customMarket","type":"bool"},{"internalType":"address","name":"iOracleInstanceAddress","type":"address"}],"internalType":"struct PositionalMarket.OracleDetails","name":"oracleDetails","type":"tuple"},{"components":[{"internalType":"uint256","name":"poolFee","type":"uint256"},{"internalType":"uint256","name":"creatorFee","type":"uint256"}],"internalType":"struct PositionalMarketManager.Fees","name":"fees","type":"tuple"}],"internalType":"struct PositionalMarketData.MarketParameters","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"asset","type":"bytes32"},{"internalType":"uint256","name":"strikeDateParam","type":"uint256"}],"name":"getMarketsForAssetAndStrikeDate","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"asset","type":"bytes32"}],"name":"getMaturityDates","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"markets","type":"address[]"},{"internalType":"enum RangedMarket.Position","name":"position","type":"uint8"}],"name":"getRangedActiveMarketsInfoPerPosition","outputs":[{"components":[{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"int256","name":"priceImpact","type":"int256"},{"internalType":"uint256","name":"leftPrice","type":"uint256"},{"internalType":"uint256","name":"rightPrice","type":"uint256"}],"internalType":"struct PositionalMarketData.RangedMarketsInfoPerPosition[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract RangedMarket","name":"market","type":"address"}],"name":"getRangedAmmMarketData","outputs":[{"components":[{"internalType":"uint256","name":"inBuyLiquidity","type":"uint256"},{"internalType":"uint256","name":"outBuyLiquidity","type":"uint256"},{"internalType":"uint256","name":"inSellLiquidity","type":"uint256"},{"internalType":"uint256","name":"outSellLiquidity","type":"uint256"},{"internalType":"uint256","name":"inBuyPrice","type":"uint256"},{"internalType":"uint256","name":"outBuyPrice","type":"uint256"},{"internalType":"uint256","name":"inSellPrice","type":"uint256"},{"internalType":"uint256","name":"outSellPrice","type":"uint256"},{"internalType":"int256","name":"inPriceImpact","type":"int256"},{"internalType":"int256","name":"outPriceImpact","type":"int256"}],"internalType":"struct PositionalMarketData.RangedAmmMarketData","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastPauseTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"nominateNewOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nominatedOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rangedMarketsAMM","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","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":"_manager","type":"address"}],"name":"setPositionalMarketManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_rangedMarketsAMM","type":"address"}],"name":"setRangedMarketsAMM","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_thalesAMM","type":"address"}],"name":"setThalesAMM","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"thalesAMM","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"proxyAddress","type":"address"}],"name":"transferOwnershipAtInit","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
608060405234801561001057600080fd5b50614aea806100206000396000f3fe608060405234801561001057600080fd5b50600436106101c45760003560e01c806379ba5097116100f9578063bf996ae311610097578063dca5f5c311610071578063dca5f5c314610487578063e153842b146104a7578063e19a8b8a146104ba578063fe4fd3e1146104da57600080fd5b8063bf996ae31461044e578063c3b83f5f14610461578063c4d66de81461047457600080fd5b80638da5cb5b116100d35780638da5cb5b146103eb57806391b4ded914610404578063961c88b71461041b578063a30c302d1461042e57600080fd5b806379ba50971461034f5780637c0f4f741461035757806389332f7f146103e357600080fd5b806352fd132c11610166578063572e36e611610140578063572e36e6146102df5780635c975abb146102f257806363c32d861461030f5780636749e0481461032f57600080fd5b806352fd132c1461028c57806353a47bb7146102ac57806353d2901c146102bf57600080fd5b80631627540c116101a25780631627540c1461022e57806316c38b3c1461024157806340915aa914610254578063481c6a751461027457600080fd5b806307b00005146101c95780631216fc7b146101f957806313af403514610219575b600080fd5b6005546101dc906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b61020c6102073660046142a2565b6104ed565b6040516101f09190614961565b61022c6102273660046142a2565b610814565b005b61022c61023c3660046142a2565b610954565b61022c61024f366004614427565b6109aa565b610267610262366004614477565b610a20565b6040516101f09190614750565b6003546101dc9061010090046001600160a01b031681565b61029f61029a366004614477565b611002565b6040516101f09190614654565b6001546101dc906001600160a01b031681565b6102d26102cd366004614336565b61131e565b6040516101f091906147a5565b6004546101dc906001600160a01b031681565b6003546102ff9060ff1681565b60405190151581526020016101f0565b61032261031d36600461445f565b6119b8565b6040516101f091906146a1565b61034261033d3660046142a2565b611c8f565b6040516101f09190614832565b61022c612558565b61036a6103653660046142a2565b612655565b6040516101f09190600061014082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160c083015260e083015160e083015261010080840151818401525061012080840151818401525092915050565b610322612c4a565b6000546101dc906201000090046001600160a01b031681565b61040d60025481565b6040519081526020016101f0565b61022c6104293660046142a2565b612ea1565b61044161043c3660046142a2565b612ef7565b6040516101f091906148dd565b61022c61045c3660046142a2565b6132e1565b61022c61046f3660046142a2565b61333f565b61022c6104823660046142a2565b613458565b61049a610495366004614554565b61351b565b6040516101f09190614819565b6102676104b5366004614477565b6135d6565b6104cd6104c83660046142e1565b613b98565b6040516101f091906146d9565b61022c6104e83660046142a2565b61405d565b6104f561412d565b600080836001600160a01b0316631069143a6040518163ffffffff1660e01b8152600401604080518083038186803b15801561053057600080fd5b505afa158015610544573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610568919061451b565b91509150600080856001600160a01b0316639e3b34bf6040518163ffffffff1660e01b8152600401604080518083038186803b1580156105a757600080fd5b505afa1580156105bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105df91906145d4565b9150915060008060008060008a6001600160a01b03166398508ecd6040518163ffffffff1660e01b815260040160a06040518083038186803b15801561062457600080fd5b505afa158015610638573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061065c91906144c5565b945094509450945094506000808c6001600160a01b0316639af1d35a6040518163ffffffff1660e01b8152600401604080518083038186803b1580156106a157600080fd5b505afa1580156106b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106d991906145d4565b9150915060006040518060a001604052808f6001600160a01b03166302d05d3f6040518163ffffffff1660e01b815260040160206040518083038186803b15801561072357600080fd5b505afa158015610737573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075b91906142c5565b6001600160a01b0316815260200160405180604001604052808f6001600160a01b031681526020018e6001600160a01b0316815250815260200160405180604001604052808d81526020018c81525081526020016040518060a001604052808b81526020018a81526020018981526020018815158152602001876001600160a01b031681525081526020016040518060400160405280868152602001858152508152509050809c50505050505050505050505050919050565b6001600160a01b03811661086f5760405162461bcd60e51b815260206004820152601960248201527f4f776e657220616464726573732063616e6e6f7420626520300000000000000060448201526064015b60405180910390fd5b600154600160a01b900460ff16156108db5760405162461bcd60e51b815260206004820152602960248201527f416c726561647920696e697469616c697a65642c20757365206e6f6d696e617460448201526832a732bba7bbb732b960b91b6064820152608401610866565b6001805460ff60a01b1916600160a01b179055600080546001600160a01b03831662010000810262010000600160b01b03199092169190911782556040805192835260208301919091527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c91015b60405180910390a150565b61095c6140b3565b600180546001600160a01b0319166001600160a01b0383169081179091556040519081527f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce2290602001610949565b6109b26140b3565b60035460ff16151581151514156109c65750565b6003805460ff191682151590811790915560ff16156109e457426002555b60035460405160ff909116151581527f8fb6c181ee25a520cf3dd6565006ef91229fcfe5a989566c2a3b8c115570cec590602001610949565b50565b60035460408051622610c560e41b815290516060926000926101009091046001600160a01b03169163e73efc9b91849184916302610c50916004808301926020929190829003018186803b158015610a7757600080fd5b505afa158015610a8b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aaf91906145bc565b6040516001600160e01b031960e085901b1681526004810192909252602482015260440160006040518083038186803b158015610aeb57600080fd5b505afa158015610aff573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610b279190810190614360565b90506000600360019054906101000a90046001600160a01b03166001600160a01b03166302610c506040518163ffffffff1660e01b815260040160206040518083038186803b158015610b7957600080fd5b505afa158015610b8d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bb191906145bc565b8411610bbd5783610c43565b600360019054906101000a90046001600160a01b03166001600160a01b03166302610c506040518163ffffffff1660e01b815260040160206040518083038186803b158015610c0b57600080fd5b505afa158015610c1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c4391906145bc565b90506000610c518683614a00565b67ffffffffffffffff811115610c7757634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610cd557816020015b610cc2604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b815260200190600190039081610c955790505b509050855b82811015610ff657838181518110610d0257634e487b7160e01b600052603260045260246000fd5b6020026020010151828883610d179190614a00565b81518110610d3557634e487b7160e01b600052603260045260246000fd5b60209081029190910101516001600160a01b0391821690526004548551911690635727a0f390869084908110610d7b57634e487b7160e01b600052603260045260246000fd5b60200260200101516040518263ffffffff1660e01b8152600401610dae91906001600160a01b0391909116815260200190565b60206040518083038186803b158015610dc657600080fd5b505afa158015610dda573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dfe9190614443565b15610fe45760045484516001600160a01b039091169063bf46c0b490869084908110610e3a57634e487b7160e01b600052603260045260246000fd5b60200260200101516000670de0b6b3a76400006040518463ffffffff1660e01b8152600401610e6b9392919061462a565b60206040518083038186803b158015610e8357600080fd5b505afa158015610e97573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ebb91906145bc565b82610ec68984614a00565b81518110610ee457634e487b7160e01b600052603260045260246000fd5b602090810291909101810151015260045484516001600160a01b039091169063bf46c0b490869084908110610f2957634e487b7160e01b600052603260045260246000fd5b60200260200101516001670de0b6b3a76400006040518463ffffffff1660e01b8152600401610f5a9392919061462a565b60206040518083038186803b158015610f7257600080fd5b505afa158015610f86573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610faa91906145bc565b82610fb58984614a00565b81518110610fd357634e487b7160e01b600052603260045260246000fd5b602002602001015160400181815250505b80610fee81614a17565b915050610cda565b50925050505b92915050565b60035460408051622610c560e41b815290516060926000926101009091046001600160a01b03169163e73efc9b91849184916302610c50916004808301926020929190829003018186803b15801561105957600080fd5b505afa15801561106d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061109191906145bc565b6040516001600160e01b031960e085901b1681526004810192909252602482015260440160006040518083038186803b1580156110cd57600080fd5b505afa1580156110e1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526111099190810190614360565b90506000815167ffffffffffffffff81111561113557634e487b7160e01b600052604160045260246000fd5b60405190808252806020026020018201604052801561115e578160200160208202803683370190505b50905060005b825181101561131557600083828151811061118f57634e487b7160e01b600052603260045260246000fd5b602002602001015190506000816001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b1580156111d457600080fd5b505afa1580156111e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061120c9190614498565b5050905087811415611300576000826001600160a01b0316639e3b34bf6040518163ffffffff1660e01b8152600401604080518083038186803b15801561125257600080fd5b505afa158015611266573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061128a91906145d4565b509050878114156112fe578584815181106112b557634e487b7160e01b600052603260045260246000fd5b60200260200101518585815181106112dd57634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b0316815250505b505b5050808061130d90614a17565b915050611164565b50949350505050565b606060008367ffffffffffffffff81111561134957634e487b7160e01b600052604160045260246000fd5b6040519080825280602002602001820160405280156113bc57816020015b6113a96040518060c0016040528060006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081525090565b8152602001906001900390816113675790505b506005549091506001600160a01b031660005b858110156119ad578686828181106113f757634e487b7160e01b600052603260045260246000fd5b905060200201602081019061140c91906142a2565b83828151811061142c57634e487b7160e01b600052603260045260246000fd5b60209081029190910101516001600160a01b039091169052600087878381811061146657634e487b7160e01b600052603260045260246000fd5b905060200201602081019061147b91906142a2565b6001600160a01b031663059692b26040518163ffffffff1660e01b815260040160206040518083038186803b1580156114b357600080fd5b505afa1580156114c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114eb91906142c5565b9050600088888481811061150f57634e487b7160e01b600052603260045260246000fd5b905060200201602081019061152491906142a2565b6001600160a01b03166392902ea96040518163ffffffff1660e01b815260040160206040518083038186803b15801561155c57600080fd5b505afa158015611570573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061159491906142c5565b90506000826001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b1580156115d157600080fd5b505afa1580156115e5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116099190614498565b509150506000826001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b15801561164857600080fd5b505afa15801561165c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116809190614498565b50915050818786815181106116a557634e487b7160e01b600052603260045260246000fd5b60200260200101516080018181525050808786815181106116d657634e487b7160e01b600052603260045260246000fd5b602002602001015160a0018181525050856001600160a01b031663efc152518c8c8881811061171557634e487b7160e01b600052603260045260246000fd5b905060200201602081019061172a91906142a2565b8b6040518363ffffffff1660e01b8152600401611748929190614604565b60206040518083038186803b15801561176057600080fd5b505afa158015611774573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061179891906145bc565b8786815181106117b857634e487b7160e01b600052603260045260246000fd5b60200260200101516040018181525050856001600160a01b031663270e13ef8c8c888181106117f757634e487b7160e01b600052603260045260246000fd5b905060200201602081019061180c91906142a2565b8b670de0b6b3a76400006040518463ffffffff1660e01b81526004016118349392919061462a565b60206040518083038186803b15801561184c57600080fd5b505afa158015611860573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061188491906145bc565b8786815181106118a457634e487b7160e01b600052603260045260246000fd5b60200260200101516020018181525050856001600160a01b0316637844dd488c8c888181106118e357634e487b7160e01b600052603260045260246000fd5b90506020020160208101906118f891906142a2565b8b6040518363ffffffff1660e01b8152600401611916929190614604565b60206040518083038186803b15801561192e57600080fd5b505afa158015611942573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061196691906145bc565b87868151811061198657634e487b7160e01b600052603260045260246000fd5b602002602001015160600181815250505050505080806119a590614a17565b9150506113cf565b509095945050505050565b60035460408051622610c560e41b815290516060926000926101009091046001600160a01b03169163e73efc9b91849184916302610c50916004808301926020929190829003018186803b158015611a0f57600080fd5b505afa158015611a23573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a4791906145bc565b6040516001600160e01b031960e085901b1681526004810192909252602482015260440160006040518083038186803b158015611a8357600080fd5b505afa158015611a97573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611abf9190810190614360565b90506000815167ffffffffffffffff811115611aeb57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015611b14578160200160208202803683370190505b50905060005b8251811015611c87576000838281518110611b4557634e487b7160e01b600052603260045260246000fd5b602002602001015190506000816001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b158015611b8a57600080fd5b505afa158015611b9e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bc29190614498565b5050905086811415611c72576000826001600160a01b0316639e3b34bf6040518163ffffffff1660e01b8152600401604080518083038186803b158015611c0857600080fd5b505afa158015611c1c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c4091906145d4565b50905080858581518110611c6457634e487b7160e01b600052603260045260246000fd5b602002602001018181525050505b50508080611c7f90614a17565b915050611b1a565b509392505050565b611d03604051806101c00160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000151581525090565b6000826001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b158015611d3e57600080fd5b505afa158015611d52573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d769190614498565b5050604080516101c081019182905260045463efc1525160e01b90925291925081906001600160a01b031663efc15251611db68760006101c48601614604565b60206040518083038186803b158015611dce57600080fd5b505afa158015611de2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e0691906145bc565b81526004805460405163efc1525160e01b81526020909301926001600160a01b039091169163efc1525191611e4091899160019101614604565b60206040518083038186803b158015611e5857600080fd5b505afa158015611e6c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e9091906145bc565b81526004805460405163613c1fc960e11b81526020909301926001600160a01b039091169163c2783f9291611eca91899160009101614604565b60206040518083038186803b158015611ee257600080fd5b505afa158015611ef6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f1a91906145bc565b81526004805460405163613c1fc960e11b81526020909301926001600160a01b039091169163c2783f9291611f5491899160019101614604565b60206040518083038186803b158015611f6c57600080fd5b505afa158015611f80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fa491906145bc565b81526004805460405163270e13ef60e01b81526020909301926001600160a01b039091169163270e13ef91611fe8918991600091670de0b6b3a7640000910161462a565b60206040518083038186803b15801561200057600080fd5b505afa158015612014573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061203891906145bc565b81526004805460405163270e13ef60e01b81526020909301926001600160a01b039091169163270e13ef9161207c918991600191670de0b6b3a7640000910161462a565b60206040518083038186803b15801561209457600080fd5b505afa1580156120a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120cc91906145bc565b8152600480546040516301e2755d60e31b81526020909301926001600160a01b0390911691630f13aae891612110918991600091670de0b6b3a7640000910161462a565b60206040518083038186803b15801561212857600080fd5b505afa15801561213c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061216091906145bc565b8152600480546040516301e2755d60e31b81526020909301926001600160a01b0390911691630f13aae8916121a4918991600191670de0b6b3a7640000910161462a565b60206040518083038186803b1580156121bc57600080fd5b505afa1580156121d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121f491906145bc565b815260048054604051632fd1b02d60e21b81526020909301926001600160a01b039091169163bf46c0b491612238918991600091670de0b6b3a7640000910161462a565b60206040518083038186803b15801561225057600080fd5b505afa158015612264573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061228891906145bc565b815260048054604051632fd1b02d60e21b81526020909301926001600160a01b039091169163bf46c0b4916122cc918991600191670de0b6b3a7640000910161462a565b60206040518083038186803b1580156122e457600080fd5b505afa1580156122f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061231c91906145bc565b815260048054604051631c37d04b60e01b81526020909301926001600160a01b0390911691631c37d04b91612360918991600091670de0b6b3a7640000910161462a565b60206040518083038186803b15801561237857600080fd5b505afa15801561238c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123b091906145bc565b815260048054604051631c37d04b60e01b81526020909301926001600160a01b0390911691631c37d04b916123f4918991600191670de0b6b3a7640000910161462a565b60206040518083038186803b15801561240c57600080fd5b505afa158015612420573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061244491906145bc565b81526004805460405163f502b00360e01b81529182018590526020909201916001600160a01b03169063f502b0039060240160206040518083038186803b15801561248e57600080fd5b505afa1580156124a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124c691906145bc565b815260048054604051635727a0f360e01b81526001600160a01b0388811693820193909352602090930192911690635727a0f39060240160206040518083038186803b15801561251557600080fd5b505afa158015612529573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061254d9190614443565b151590529392505050565b6001546001600160a01b031633146125d05760405162461bcd60e51b815260206004820152603560248201527f596f75206d757374206265206e6f6d696e61746564206265666f726520796f7560448201527402063616e20616363657074206f776e65727368697605c1b6064820152608401610866565b60005460015460408051620100009093046001600160a01b03908116845290911660208301527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c910160405180910390a1600180546000805462010000600160b01b0319166001600160a01b03831662010000021790556001600160a01b0319169055565b6126ab604051806101400160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040805161014081019182905260055463efc1525160e01b9092529081906001600160a01b031663efc152516126e78660006101448601614604565b60206040518083038186803b1580156126ff57600080fd5b505afa158015612713573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061273791906145bc565b815260055460405163efc1525160e01b81526020909201916001600160a01b039091169063efc1525190612772908790600190600401614604565b60206040518083038186803b15801561278a57600080fd5b505afa15801561279e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127c291906145bc565b815260055460405163613c1fc960e11b81526020909201916001600160a01b039091169063c2783f92906127fd908790600090600401614604565b60206040518083038186803b15801561281557600080fd5b505afa158015612829573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061284d91906145bc565b815260055460405163613c1fc960e11b81526020909201916001600160a01b039091169063c2783f9290612888908790600190600401614604565b60206040518083038186803b1580156128a057600080fd5b505afa1580156128b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128d891906145bc565b815260055460405163270e13ef60e01b81526020909201916001600160a01b039091169063270e13ef9061291d908790600090670de0b6b3a76400009060040161462a565b60206040518083038186803b15801561293557600080fd5b505afa158015612949573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061296d91906145bc565b815260055460405163270e13ef60e01b81526020909201916001600160a01b039091169063270e13ef906129b2908790600190670de0b6b3a76400009060040161462a565b60206040518083038186803b1580156129ca57600080fd5b505afa1580156129de573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a0291906145bc565b81526005546040516301e2755d60e31b81526020909201916001600160a01b0390911690630f13aae890612a47908790600090670de0b6b3a76400009060040161462a565b60206040518083038186803b158015612a5f57600080fd5b505afa158015612a73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a9791906145bc565b81526005546040516301e2755d60e31b81526020909201916001600160a01b0390911690630f13aae890612adc908790600190670de0b6b3a76400009060040161462a565b60206040518083038186803b158015612af457600080fd5b505afa158015612b08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b2c91906145bc565b8152600554604051630f089ba960e31b81526020909201916001600160a01b0390911690637844dd4890612b67908790600090600401614604565b60206040518083038186803b158015612b7f57600080fd5b505afa158015612b93573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bb791906145bc565b8152600554604051630f089ba960e31b81526020909201916001600160a01b0390911690637844dd4890612bf2908790600190600401614604565b60206040518083038186803b158015612c0a57600080fd5b505afa158015612c1e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c4291906145bc565b905292915050565b60035460408051622610c560e41b815290516060926000926101009091046001600160a01b03169163e73efc9b91849184916302610c50916004808301926020929190829003018186803b158015612ca157600080fd5b505afa158015612cb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cd991906145bc565b6040516001600160e01b031960e085901b1681526004810192909252602482015260440160006040518083038186803b158015612d1557600080fd5b505afa158015612d29573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612d519190810190614360565b90506000815167ffffffffffffffff811115612d7d57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015612da6578160200160208202803683370190505b50905060005b8251811015612e9a576000838281518110612dd757634e487b7160e01b600052603260045260246000fd5b602002602001015190506000816001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b158015612e1c57600080fd5b505afa158015612e30573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e549190614498565b5050905080848481518110612e7957634e487b7160e01b600052603260045260246000fd5b60200260200101818152505050508080612e9290614a17565b915050612dac565b5092915050565b612ea96140b3565b600480546001600160a01b0319166001600160a01b0383169081179091556040519081527f19f7cac3fd754f5bcb74a54047601c1915d9c53a239d1fac75e10979ced732c190602001610949565b612eff6141ef565b600080836001600160a01b031663c7a5bdc86040518163ffffffff1660e01b8152600401604080518083038186803b158015612f3a57600080fd5b505afa158015612f4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f7291906145d4565b91509150600080856001600160a01b031663d068cdc56040518163ffffffff1660e01b8152600401604080518083038186803b158015612fb157600080fd5b505afa158015612fc5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fe991906145d4565b915091506040518060c0016040528060405180604001604052808781526020018681525081526020016040518060200160405280896001600160a01b031663eef49ee36040518163ffffffff1660e01b815260040160206040518083038186803b15801561305657600080fd5b505afa15801561306a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061308e91906145bc565b81525081526020016040518060400160405280896001600160a01b0316633f6fa6556040518163ffffffff1660e01b815260040160206040518083038186803b1580156130da57600080fd5b505afa1580156130ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131129190614443565b15158152602001896001600160a01b031663ac3791e36040518163ffffffff1660e01b815260040160206040518083038186803b15801561315257600080fd5b505afa158015613166573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061318a9190614443565b15158152508152602001876001600160a01b031663b1c9fe6e6040518163ffffffff1660e01b815260040160206040518083038186803b1580156131cd57600080fd5b505afa1580156131e1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132059190614581565b600281111561322457634e487b7160e01b600052602160045260246000fd5b8152602001876001600160a01b031663653721476040518163ffffffff1660e01b815260040160206040518083038186803b15801561326257600080fd5b505afa158015613276573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061329a91906145a0565b60018111156132b957634e487b7160e01b600052602160045260246000fd5b8152602001604051806040016040528085815260200184815250815250945050505050919050565b6132e96140b3565b60038054610100600160a81b0319166101006001600160a01b038416908102919091179091556040519081527f953db4c0eb104316531cd43d8be60ae666e058cbc59c11cb84d5cadb57f42f2f90602001610949565b6133476140b3565b6001600160a01b03811661338f5760405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b6044820152606401610866565b600154600160a81b900460ff16156133df5760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481d1c985b9cd9995c9c9959606a1b6044820152606401610866565b600080546001600160a01b038381166201000081810262010000600160b01b031990941693909317938490556001805460ff60a81b1916600160a81b1790556040805193909404909116825260208201527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9101610949565b600054610100900460ff166134735760005460ff1615613477565b303b155b6134da5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610866565b600054610100900460ff161580156134fc576000805461ffff19166101011790555b61350582610814565b8015613517576000805461ff00191690555b5050565b6040805160608101825260006020820181815292820152908152604051636392a51f60e01b81526001600160a01b0383811660048301526000918291861690636392a51f90602401604080518083038186803b15801561357a57600080fd5b505afa15801561358e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135b291906145d4565b60408051606081018252602081019384529081019190915290815295945050505050565b60035460408051622610c560e41b815290516060926000926101009091046001600160a01b03169163e73efc9b91849184916302610c50916004808301926020929190829003018186803b15801561362d57600080fd5b505afa158015613641573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061366591906145bc565b6040516001600160e01b031960e085901b1681526004810192909252602482015260440160006040518083038186803b1580156136a157600080fd5b505afa1580156136b5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526136dd9190810190614360565b90506000600360019054906101000a90046001600160a01b03166001600160a01b03166302610c506040518163ffffffff1660e01b815260040160206040518083038186803b15801561372f57600080fd5b505afa158015613743573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061376791906145bc565b841161377357836137f9565b600360019054906101000a90046001600160a01b03166001600160a01b03166302610c506040518163ffffffff1660e01b815260040160206040518083038186803b1580156137c157600080fd5b505afa1580156137d5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137f991906145bc565b905060006138078683614a00565b67ffffffffffffffff81111561382d57634e487b7160e01b600052604160045260246000fd5b60405190808252806020026020018201604052801561388b57816020015b613878604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b81526020019060019003908161384b5790505b509050855b82811015610ff6578381815181106138b857634e487b7160e01b600052603260045260246000fd5b60200260200101518288836138cd9190614a00565b815181106138eb57634e487b7160e01b600052603260045260246000fd5b60209081029190910101516001600160a01b0391821690526004548551911690635727a0f39086908490811061393157634e487b7160e01b600052603260045260246000fd5b60200260200101516040518263ffffffff1660e01b815260040161396491906001600160a01b0391909116815260200190565b60206040518083038186803b15801561397c57600080fd5b505afa158015613990573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139b49190614443565b15613b865760045484516001600160a01b0390911690636ed033f8908690849081106139f057634e487b7160e01b600052603260045260246000fd5b602002602001015160006040518363ffffffff1660e01b8152600401613a17929190614604565b60206040518083038186803b158015613a2f57600080fd5b505afa158015613a43573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a6791906145bc565b82613a728984614a00565b81518110613a9057634e487b7160e01b600052603260045260246000fd5b602090810291909101810151015260045484516001600160a01b0390911690636ed033f890869084908110613ad557634e487b7160e01b600052603260045260246000fd5b602002602001015160016040518363ffffffff1660e01b8152600401613afc929190614604565b60206040518083038186803b158015613b1457600080fd5b505afa158015613b28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b4c91906145bc565b82613b578984614a00565b81518110613b7557634e487b7160e01b600052603260045260246000fd5b602002602001015160400181815250505b80613b9081614a17565b915050613890565b606060008367ffffffffffffffff811115613bc357634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015613c2f57816020015b613c1c6040518060a0016040528060006001600160a01b03168152602001600081526020016000815260200160008152602001600081525090565b815260200190600190039081613be15790505b50905060005b8481101561131557858582818110613c5d57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190613c7291906142a2565b828281518110613c9257634e487b7160e01b600052603260045260246000fd5b60209081029190910101516001600160a01b0390911690526000868683818110613ccc57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190613ce191906142a2565b90506000816001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b158015613d1e57600080fd5b505afa158015613d32573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d569190614498565b5091505080848481518110613d7b57634e487b7160e01b600052603260045260246000fd5b6020908102919091010151608001526004546001600160a01b031663efc15251898986818110613dbb57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190613dd091906142a2565b886040518363ffffffff1660e01b8152600401613dee929190614604565b60206040518083038186803b158015613e0657600080fd5b505afa158015613e1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e3e91906145bc565b848481518110613e5e57634e487b7160e01b600052603260045260246000fd5b6020908102919091010151604001526004546001600160a01b031663bf46c0b4898986818110613e9e57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190613eb391906142a2565b88670de0b6b3a76400006040518463ffffffff1660e01b8152600401613edb9392919061462a565b60206040518083038186803b158015613ef357600080fd5b505afa158015613f07573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f2b91906145bc565b848481518110613f4b57634e487b7160e01b600052603260045260246000fd5b6020908102919091010151606001526004546001600160a01b031663270e13ef898986818110613f8b57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190613fa091906142a2565b88670de0b6b3a76400006040518463ffffffff1660e01b8152600401613fc89392919061462a565b60206040518083038186803b158015613fe057600080fd5b505afa158015613ff4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061401891906145bc565b84848151811061403857634e487b7160e01b600052603260045260246000fd5b602002602001015160200181815250505050808061405590614a17565b915050613c35565b6140656140b3565b600580546001600160a01b0319166001600160a01b0383169081179091556040519081527f9f74cb0bcc60fb8fa09e2ee2a8a5da11b641195aa499c69210dd8c0ed9cf34e390602001610949565b6000546201000090046001600160a01b0316331461412b5760405162461bcd60e51b815260206004820152602f60248201527f4f6e6c792074686520636f6e7472616374206f776e6572206d6179207065726660448201526e37b936903a3434b99030b1ba34b7b760891b6064820152608401610866565b565b6040518060a0016040528060006001600160a01b03168152602001614177604051806040016040528060006001600160a01b0316815260200160006001600160a01b031681525090565b8152602001614199604051806040016040528060008152602001600081525090565b81526040805160a081018252600080825260208281018290529282018190526060820181905260808201529101905b81526020016141ea604051806040016040528060008152602001600081525090565b905290565b6040805161010081018252600060c0820181815260e083018290528252825160208082018552828252808401919091528351808501855282815290810191909152909182019081526020016000815260200160006141c8565b805161425381614a84565b919050565b60008083601f840112614269578081fd5b50813567ffffffffffffffff811115614280578182fd5b6020830191508360208260051b850101111561429b57600080fd5b9250929050565b6000602082840312156142b3578081fd5b81356142be81614a84565b9392505050565b6000602082840312156142d6578081fd5b81516142be81614a84565b6000806000604084860312156142f5578182fd5b833567ffffffffffffffff81111561430b578283fd5b61431786828701614258565b909450925050602084013561432b81614aa7565b809150509250925092565b60008060006040848603121561434a578283fd5b833567ffffffffffffffff81111561430b578384fd5b60006020808385031215614372578182fd5b825167ffffffffffffffff80821115614389578384fd5b818501915085601f83011261439c578384fd5b8151818111156143ae576143ae614a5e565b8060051b604051601f19603f830116810181811085821117156143d3576143d3614a5e565b604052828152858101935084860182860187018a10156143f1578788fd5b8795505b8386101561441a5761440681614248565b8552600195909501949386019386016143f5565b5098975050505050505050565b600060208284031215614438578081fd5b81356142be81614a99565b600060208284031215614454578081fd5b81516142be81614a99565b600060208284031215614470578081fd5b5035919050565b60008060408385031215614489578182fd5b50508035926020909101359150565b6000806000606084860312156144ac578081fd5b8351925060208401519150604084015190509250925092565b600080600080600060a086880312156144dc578283fd5b85519450602086015193506040860151925060608601516144fc81614a99565b608087015190925061450d81614a84565b809150509295509295909350565b6000806040838503121561452d578182fd5b825161453881614a84565b602084015190925061454981614a84565b809150509250929050565b60008060408385031215614566578182fd5b823561457181614a84565b9150602083013561454981614a84565b600060208284031215614592578081fd5b8151600381106142be578182fd5b6000602082840312156145b1578081fd5b81516142be81614aa7565b6000602082840312156145cd578081fd5b5051919050565b600080604083850312156145e6578182fd5b505080516020909101519092909150565b61460081614a74565b9052565b6001600160a01b03831681526040810161461d83614a74565b8260208301529392505050565b6001600160a01b03841681526060810161464384614a74565b602082019390935260400152919050565b6020808252825182820181905260009190848201906040850190845b818110156146955783516001600160a01b031683529284019291840191600101614670565b50909695505050505050565b6020808252825182820181905260009190848201906040850190845b81811015614695578351835292840192918401916001016146bd565b602080825282518282018190526000919060409081850190868401855b8281101561474357815180516001600160a01b0316855286810151878601528581015186860152606080820151908601526080908101519085015260a090930192908501906001016146f6565b5091979650505050505050565b602080825282518282018190526000919060409081850190868401855b8281101561474357815180516001600160a01b031685528681015187860152850151858501526060909301929085019060010161476d565b602080825282518282018190526000919060409081850190868401855b8281101561474357815180516001600160a01b0316855286810151878601528581015186860152606080820151908601526080808201519086015260a0908101519085015260c090930192908501906001016147c2565b8151805182526020908101519082015260408101610ffc565b60006101c082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160c083015260e083015160e08301526101008084015181840152506101208084015181840152506101408084015181840152506101608084015181840152506101808084015181840152506101a0808401516148d58285018215159052565b505092915050565b815180518252602090810151908201526101208101602083015151604083015260408301518051151560608401526020810151151560808401525060608301516003811061492d5761492d614a48565b60a0830152608083015161494460c08401826145f7565b5060a0830151805160e08401526020810151610100840152612e9a565b81516001600160a01b039081168252602080840151805183168285015281015182166040808501919091528401518051606085015290810151608084015261018083019190506060840151805160a0850152602081015160c0850152604081015160e0850152606081015115156101008501528160808201511661012085015250506080830151612e9a61014084018280518252602090810151910152565b600082821015614a1257614a12614a32565b500390565b6000600019821415614a2b57614a2b614a32565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b60028110610a1d57610a1d614a48565b6001600160a01b0381168114610a1d57600080fd5b8015158114610a1d57600080fd5b60028110610a1d57600080fdfea26469706673582212208d276e4f7c73b6eae6539870115e28649300eb6ba13b51ac6c98e6507d9042f164736f6c63430008040033
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106101c45760003560e01c806379ba5097116100f9578063bf996ae311610097578063dca5f5c311610071578063dca5f5c314610487578063e153842b146104a7578063e19a8b8a146104ba578063fe4fd3e1146104da57600080fd5b8063bf996ae31461044e578063c3b83f5f14610461578063c4d66de81461047457600080fd5b80638da5cb5b116100d35780638da5cb5b146103eb57806391b4ded914610404578063961c88b71461041b578063a30c302d1461042e57600080fd5b806379ba50971461034f5780637c0f4f741461035757806389332f7f146103e357600080fd5b806352fd132c11610166578063572e36e611610140578063572e36e6146102df5780635c975abb146102f257806363c32d861461030f5780636749e0481461032f57600080fd5b806352fd132c1461028c57806353a47bb7146102ac57806353d2901c146102bf57600080fd5b80631627540c116101a25780631627540c1461022e57806316c38b3c1461024157806340915aa914610254578063481c6a751461027457600080fd5b806307b00005146101c95780631216fc7b146101f957806313af403514610219575b600080fd5b6005546101dc906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b61020c6102073660046142a2565b6104ed565b6040516101f09190614961565b61022c6102273660046142a2565b610814565b005b61022c61023c3660046142a2565b610954565b61022c61024f366004614427565b6109aa565b610267610262366004614477565b610a20565b6040516101f09190614750565b6003546101dc9061010090046001600160a01b031681565b61029f61029a366004614477565b611002565b6040516101f09190614654565b6001546101dc906001600160a01b031681565b6102d26102cd366004614336565b61131e565b6040516101f091906147a5565b6004546101dc906001600160a01b031681565b6003546102ff9060ff1681565b60405190151581526020016101f0565b61032261031d36600461445f565b6119b8565b6040516101f091906146a1565b61034261033d3660046142a2565b611c8f565b6040516101f09190614832565b61022c612558565b61036a6103653660046142a2565b612655565b6040516101f09190600061014082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160c083015260e083015160e083015261010080840151818401525061012080840151818401525092915050565b610322612c4a565b6000546101dc906201000090046001600160a01b031681565b61040d60025481565b6040519081526020016101f0565b61022c6104293660046142a2565b612ea1565b61044161043c3660046142a2565b612ef7565b6040516101f091906148dd565b61022c61045c3660046142a2565b6132e1565b61022c61046f3660046142a2565b61333f565b61022c6104823660046142a2565b613458565b61049a610495366004614554565b61351b565b6040516101f09190614819565b6102676104b5366004614477565b6135d6565b6104cd6104c83660046142e1565b613b98565b6040516101f091906146d9565b61022c6104e83660046142a2565b61405d565b6104f561412d565b600080836001600160a01b0316631069143a6040518163ffffffff1660e01b8152600401604080518083038186803b15801561053057600080fd5b505afa158015610544573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610568919061451b565b91509150600080856001600160a01b0316639e3b34bf6040518163ffffffff1660e01b8152600401604080518083038186803b1580156105a757600080fd5b505afa1580156105bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105df91906145d4565b9150915060008060008060008a6001600160a01b03166398508ecd6040518163ffffffff1660e01b815260040160a06040518083038186803b15801561062457600080fd5b505afa158015610638573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061065c91906144c5565b945094509450945094506000808c6001600160a01b0316639af1d35a6040518163ffffffff1660e01b8152600401604080518083038186803b1580156106a157600080fd5b505afa1580156106b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106d991906145d4565b9150915060006040518060a001604052808f6001600160a01b03166302d05d3f6040518163ffffffff1660e01b815260040160206040518083038186803b15801561072357600080fd5b505afa158015610737573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075b91906142c5565b6001600160a01b0316815260200160405180604001604052808f6001600160a01b031681526020018e6001600160a01b0316815250815260200160405180604001604052808d81526020018c81525081526020016040518060a001604052808b81526020018a81526020018981526020018815158152602001876001600160a01b031681525081526020016040518060400160405280868152602001858152508152509050809c50505050505050505050505050919050565b6001600160a01b03811661086f5760405162461bcd60e51b815260206004820152601960248201527f4f776e657220616464726573732063616e6e6f7420626520300000000000000060448201526064015b60405180910390fd5b600154600160a01b900460ff16156108db5760405162461bcd60e51b815260206004820152602960248201527f416c726561647920696e697469616c697a65642c20757365206e6f6d696e617460448201526832a732bba7bbb732b960b91b6064820152608401610866565b6001805460ff60a01b1916600160a01b179055600080546001600160a01b03831662010000810262010000600160b01b03199092169190911782556040805192835260208301919091527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c91015b60405180910390a150565b61095c6140b3565b600180546001600160a01b0319166001600160a01b0383169081179091556040519081527f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce2290602001610949565b6109b26140b3565b60035460ff16151581151514156109c65750565b6003805460ff191682151590811790915560ff16156109e457426002555b60035460405160ff909116151581527f8fb6c181ee25a520cf3dd6565006ef91229fcfe5a989566c2a3b8c115570cec590602001610949565b50565b60035460408051622610c560e41b815290516060926000926101009091046001600160a01b03169163e73efc9b91849184916302610c50916004808301926020929190829003018186803b158015610a7757600080fd5b505afa158015610a8b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aaf91906145bc565b6040516001600160e01b031960e085901b1681526004810192909252602482015260440160006040518083038186803b158015610aeb57600080fd5b505afa158015610aff573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610b279190810190614360565b90506000600360019054906101000a90046001600160a01b03166001600160a01b03166302610c506040518163ffffffff1660e01b815260040160206040518083038186803b158015610b7957600080fd5b505afa158015610b8d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bb191906145bc565b8411610bbd5783610c43565b600360019054906101000a90046001600160a01b03166001600160a01b03166302610c506040518163ffffffff1660e01b815260040160206040518083038186803b158015610c0b57600080fd5b505afa158015610c1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c4391906145bc565b90506000610c518683614a00565b67ffffffffffffffff811115610c7757634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610cd557816020015b610cc2604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b815260200190600190039081610c955790505b509050855b82811015610ff657838181518110610d0257634e487b7160e01b600052603260045260246000fd5b6020026020010151828883610d179190614a00565b81518110610d3557634e487b7160e01b600052603260045260246000fd5b60209081029190910101516001600160a01b0391821690526004548551911690635727a0f390869084908110610d7b57634e487b7160e01b600052603260045260246000fd5b60200260200101516040518263ffffffff1660e01b8152600401610dae91906001600160a01b0391909116815260200190565b60206040518083038186803b158015610dc657600080fd5b505afa158015610dda573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dfe9190614443565b15610fe45760045484516001600160a01b039091169063bf46c0b490869084908110610e3a57634e487b7160e01b600052603260045260246000fd5b60200260200101516000670de0b6b3a76400006040518463ffffffff1660e01b8152600401610e6b9392919061462a565b60206040518083038186803b158015610e8357600080fd5b505afa158015610e97573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ebb91906145bc565b82610ec68984614a00565b81518110610ee457634e487b7160e01b600052603260045260246000fd5b602090810291909101810151015260045484516001600160a01b039091169063bf46c0b490869084908110610f2957634e487b7160e01b600052603260045260246000fd5b60200260200101516001670de0b6b3a76400006040518463ffffffff1660e01b8152600401610f5a9392919061462a565b60206040518083038186803b158015610f7257600080fd5b505afa158015610f86573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610faa91906145bc565b82610fb58984614a00565b81518110610fd357634e487b7160e01b600052603260045260246000fd5b602002602001015160400181815250505b80610fee81614a17565b915050610cda565b50925050505b92915050565b60035460408051622610c560e41b815290516060926000926101009091046001600160a01b03169163e73efc9b91849184916302610c50916004808301926020929190829003018186803b15801561105957600080fd5b505afa15801561106d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061109191906145bc565b6040516001600160e01b031960e085901b1681526004810192909252602482015260440160006040518083038186803b1580156110cd57600080fd5b505afa1580156110e1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526111099190810190614360565b90506000815167ffffffffffffffff81111561113557634e487b7160e01b600052604160045260246000fd5b60405190808252806020026020018201604052801561115e578160200160208202803683370190505b50905060005b825181101561131557600083828151811061118f57634e487b7160e01b600052603260045260246000fd5b602002602001015190506000816001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b1580156111d457600080fd5b505afa1580156111e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061120c9190614498565b5050905087811415611300576000826001600160a01b0316639e3b34bf6040518163ffffffff1660e01b8152600401604080518083038186803b15801561125257600080fd5b505afa158015611266573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061128a91906145d4565b509050878114156112fe578584815181106112b557634e487b7160e01b600052603260045260246000fd5b60200260200101518585815181106112dd57634e487b7160e01b600052603260045260246000fd5b60200260200101906001600160a01b031690816001600160a01b0316815250505b505b5050808061130d90614a17565b915050611164565b50949350505050565b606060008367ffffffffffffffff81111561134957634e487b7160e01b600052604160045260246000fd5b6040519080825280602002602001820160405280156113bc57816020015b6113a96040518060c0016040528060006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081525090565b8152602001906001900390816113675790505b506005549091506001600160a01b031660005b858110156119ad578686828181106113f757634e487b7160e01b600052603260045260246000fd5b905060200201602081019061140c91906142a2565b83828151811061142c57634e487b7160e01b600052603260045260246000fd5b60209081029190910101516001600160a01b039091169052600087878381811061146657634e487b7160e01b600052603260045260246000fd5b905060200201602081019061147b91906142a2565b6001600160a01b031663059692b26040518163ffffffff1660e01b815260040160206040518083038186803b1580156114b357600080fd5b505afa1580156114c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114eb91906142c5565b9050600088888481811061150f57634e487b7160e01b600052603260045260246000fd5b905060200201602081019061152491906142a2565b6001600160a01b03166392902ea96040518163ffffffff1660e01b815260040160206040518083038186803b15801561155c57600080fd5b505afa158015611570573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061159491906142c5565b90506000826001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b1580156115d157600080fd5b505afa1580156115e5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116099190614498565b509150506000826001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b15801561164857600080fd5b505afa15801561165c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116809190614498565b50915050818786815181106116a557634e487b7160e01b600052603260045260246000fd5b60200260200101516080018181525050808786815181106116d657634e487b7160e01b600052603260045260246000fd5b602002602001015160a0018181525050856001600160a01b031663efc152518c8c8881811061171557634e487b7160e01b600052603260045260246000fd5b905060200201602081019061172a91906142a2565b8b6040518363ffffffff1660e01b8152600401611748929190614604565b60206040518083038186803b15801561176057600080fd5b505afa158015611774573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061179891906145bc565b8786815181106117b857634e487b7160e01b600052603260045260246000fd5b60200260200101516040018181525050856001600160a01b031663270e13ef8c8c888181106117f757634e487b7160e01b600052603260045260246000fd5b905060200201602081019061180c91906142a2565b8b670de0b6b3a76400006040518463ffffffff1660e01b81526004016118349392919061462a565b60206040518083038186803b15801561184c57600080fd5b505afa158015611860573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061188491906145bc565b8786815181106118a457634e487b7160e01b600052603260045260246000fd5b60200260200101516020018181525050856001600160a01b0316637844dd488c8c888181106118e357634e487b7160e01b600052603260045260246000fd5b90506020020160208101906118f891906142a2565b8b6040518363ffffffff1660e01b8152600401611916929190614604565b60206040518083038186803b15801561192e57600080fd5b505afa158015611942573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061196691906145bc565b87868151811061198657634e487b7160e01b600052603260045260246000fd5b602002602001015160600181815250505050505080806119a590614a17565b9150506113cf565b509095945050505050565b60035460408051622610c560e41b815290516060926000926101009091046001600160a01b03169163e73efc9b91849184916302610c50916004808301926020929190829003018186803b158015611a0f57600080fd5b505afa158015611a23573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a4791906145bc565b6040516001600160e01b031960e085901b1681526004810192909252602482015260440160006040518083038186803b158015611a8357600080fd5b505afa158015611a97573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611abf9190810190614360565b90506000815167ffffffffffffffff811115611aeb57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015611b14578160200160208202803683370190505b50905060005b8251811015611c87576000838281518110611b4557634e487b7160e01b600052603260045260246000fd5b602002602001015190506000816001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b158015611b8a57600080fd5b505afa158015611b9e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bc29190614498565b5050905086811415611c72576000826001600160a01b0316639e3b34bf6040518163ffffffff1660e01b8152600401604080518083038186803b158015611c0857600080fd5b505afa158015611c1c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c4091906145d4565b50905080858581518110611c6457634e487b7160e01b600052603260045260246000fd5b602002602001018181525050505b50508080611c7f90614a17565b915050611b1a565b509392505050565b611d03604051806101c00160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000151581525090565b6000826001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b158015611d3e57600080fd5b505afa158015611d52573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d769190614498565b5050604080516101c081019182905260045463efc1525160e01b90925291925081906001600160a01b031663efc15251611db68760006101c48601614604565b60206040518083038186803b158015611dce57600080fd5b505afa158015611de2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e0691906145bc565b81526004805460405163efc1525160e01b81526020909301926001600160a01b039091169163efc1525191611e4091899160019101614604565b60206040518083038186803b158015611e5857600080fd5b505afa158015611e6c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e9091906145bc565b81526004805460405163613c1fc960e11b81526020909301926001600160a01b039091169163c2783f9291611eca91899160009101614604565b60206040518083038186803b158015611ee257600080fd5b505afa158015611ef6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f1a91906145bc565b81526004805460405163613c1fc960e11b81526020909301926001600160a01b039091169163c2783f9291611f5491899160019101614604565b60206040518083038186803b158015611f6c57600080fd5b505afa158015611f80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fa491906145bc565b81526004805460405163270e13ef60e01b81526020909301926001600160a01b039091169163270e13ef91611fe8918991600091670de0b6b3a7640000910161462a565b60206040518083038186803b15801561200057600080fd5b505afa158015612014573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061203891906145bc565b81526004805460405163270e13ef60e01b81526020909301926001600160a01b039091169163270e13ef9161207c918991600191670de0b6b3a7640000910161462a565b60206040518083038186803b15801561209457600080fd5b505afa1580156120a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120cc91906145bc565b8152600480546040516301e2755d60e31b81526020909301926001600160a01b0390911691630f13aae891612110918991600091670de0b6b3a7640000910161462a565b60206040518083038186803b15801561212857600080fd5b505afa15801561213c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061216091906145bc565b8152600480546040516301e2755d60e31b81526020909301926001600160a01b0390911691630f13aae8916121a4918991600191670de0b6b3a7640000910161462a565b60206040518083038186803b1580156121bc57600080fd5b505afa1580156121d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121f491906145bc565b815260048054604051632fd1b02d60e21b81526020909301926001600160a01b039091169163bf46c0b491612238918991600091670de0b6b3a7640000910161462a565b60206040518083038186803b15801561225057600080fd5b505afa158015612264573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061228891906145bc565b815260048054604051632fd1b02d60e21b81526020909301926001600160a01b039091169163bf46c0b4916122cc918991600191670de0b6b3a7640000910161462a565b60206040518083038186803b1580156122e457600080fd5b505afa1580156122f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061231c91906145bc565b815260048054604051631c37d04b60e01b81526020909301926001600160a01b0390911691631c37d04b91612360918991600091670de0b6b3a7640000910161462a565b60206040518083038186803b15801561237857600080fd5b505afa15801561238c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123b091906145bc565b815260048054604051631c37d04b60e01b81526020909301926001600160a01b0390911691631c37d04b916123f4918991600191670de0b6b3a7640000910161462a565b60206040518083038186803b15801561240c57600080fd5b505afa158015612420573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061244491906145bc565b81526004805460405163f502b00360e01b81529182018590526020909201916001600160a01b03169063f502b0039060240160206040518083038186803b15801561248e57600080fd5b505afa1580156124a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124c691906145bc565b815260048054604051635727a0f360e01b81526001600160a01b0388811693820193909352602090930192911690635727a0f39060240160206040518083038186803b15801561251557600080fd5b505afa158015612529573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061254d9190614443565b151590529392505050565b6001546001600160a01b031633146125d05760405162461bcd60e51b815260206004820152603560248201527f596f75206d757374206265206e6f6d696e61746564206265666f726520796f7560448201527402063616e20616363657074206f776e65727368697605c1b6064820152608401610866565b60005460015460408051620100009093046001600160a01b03908116845290911660208301527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c910160405180910390a1600180546000805462010000600160b01b0319166001600160a01b03831662010000021790556001600160a01b0319169055565b6126ab604051806101400160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040805161014081019182905260055463efc1525160e01b9092529081906001600160a01b031663efc152516126e78660006101448601614604565b60206040518083038186803b1580156126ff57600080fd5b505afa158015612713573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061273791906145bc565b815260055460405163efc1525160e01b81526020909201916001600160a01b039091169063efc1525190612772908790600190600401614604565b60206040518083038186803b15801561278a57600080fd5b505afa15801561279e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127c291906145bc565b815260055460405163613c1fc960e11b81526020909201916001600160a01b039091169063c2783f92906127fd908790600090600401614604565b60206040518083038186803b15801561281557600080fd5b505afa158015612829573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061284d91906145bc565b815260055460405163613c1fc960e11b81526020909201916001600160a01b039091169063c2783f9290612888908790600190600401614604565b60206040518083038186803b1580156128a057600080fd5b505afa1580156128b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128d891906145bc565b815260055460405163270e13ef60e01b81526020909201916001600160a01b039091169063270e13ef9061291d908790600090670de0b6b3a76400009060040161462a565b60206040518083038186803b15801561293557600080fd5b505afa158015612949573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061296d91906145bc565b815260055460405163270e13ef60e01b81526020909201916001600160a01b039091169063270e13ef906129b2908790600190670de0b6b3a76400009060040161462a565b60206040518083038186803b1580156129ca57600080fd5b505afa1580156129de573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a0291906145bc565b81526005546040516301e2755d60e31b81526020909201916001600160a01b0390911690630f13aae890612a47908790600090670de0b6b3a76400009060040161462a565b60206040518083038186803b158015612a5f57600080fd5b505afa158015612a73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a9791906145bc565b81526005546040516301e2755d60e31b81526020909201916001600160a01b0390911690630f13aae890612adc908790600190670de0b6b3a76400009060040161462a565b60206040518083038186803b158015612af457600080fd5b505afa158015612b08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b2c91906145bc565b8152600554604051630f089ba960e31b81526020909201916001600160a01b0390911690637844dd4890612b67908790600090600401614604565b60206040518083038186803b158015612b7f57600080fd5b505afa158015612b93573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bb791906145bc565b8152600554604051630f089ba960e31b81526020909201916001600160a01b0390911690637844dd4890612bf2908790600190600401614604565b60206040518083038186803b158015612c0a57600080fd5b505afa158015612c1e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c4291906145bc565b905292915050565b60035460408051622610c560e41b815290516060926000926101009091046001600160a01b03169163e73efc9b91849184916302610c50916004808301926020929190829003018186803b158015612ca157600080fd5b505afa158015612cb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cd991906145bc565b6040516001600160e01b031960e085901b1681526004810192909252602482015260440160006040518083038186803b158015612d1557600080fd5b505afa158015612d29573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612d519190810190614360565b90506000815167ffffffffffffffff811115612d7d57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015612da6578160200160208202803683370190505b50905060005b8251811015612e9a576000838281518110612dd757634e487b7160e01b600052603260045260246000fd5b602002602001015190506000816001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b158015612e1c57600080fd5b505afa158015612e30573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e549190614498565b5050905080848481518110612e7957634e487b7160e01b600052603260045260246000fd5b60200260200101818152505050508080612e9290614a17565b915050612dac565b5092915050565b612ea96140b3565b600480546001600160a01b0319166001600160a01b0383169081179091556040519081527f19f7cac3fd754f5bcb74a54047601c1915d9c53a239d1fac75e10979ced732c190602001610949565b612eff6141ef565b600080836001600160a01b031663c7a5bdc86040518163ffffffff1660e01b8152600401604080518083038186803b158015612f3a57600080fd5b505afa158015612f4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f7291906145d4565b91509150600080856001600160a01b031663d068cdc56040518163ffffffff1660e01b8152600401604080518083038186803b158015612fb157600080fd5b505afa158015612fc5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fe991906145d4565b915091506040518060c0016040528060405180604001604052808781526020018681525081526020016040518060200160405280896001600160a01b031663eef49ee36040518163ffffffff1660e01b815260040160206040518083038186803b15801561305657600080fd5b505afa15801561306a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061308e91906145bc565b81525081526020016040518060400160405280896001600160a01b0316633f6fa6556040518163ffffffff1660e01b815260040160206040518083038186803b1580156130da57600080fd5b505afa1580156130ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131129190614443565b15158152602001896001600160a01b031663ac3791e36040518163ffffffff1660e01b815260040160206040518083038186803b15801561315257600080fd5b505afa158015613166573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061318a9190614443565b15158152508152602001876001600160a01b031663b1c9fe6e6040518163ffffffff1660e01b815260040160206040518083038186803b1580156131cd57600080fd5b505afa1580156131e1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132059190614581565b600281111561322457634e487b7160e01b600052602160045260246000fd5b8152602001876001600160a01b031663653721476040518163ffffffff1660e01b815260040160206040518083038186803b15801561326257600080fd5b505afa158015613276573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061329a91906145a0565b60018111156132b957634e487b7160e01b600052602160045260246000fd5b8152602001604051806040016040528085815260200184815250815250945050505050919050565b6132e96140b3565b60038054610100600160a81b0319166101006001600160a01b038416908102919091179091556040519081527f953db4c0eb104316531cd43d8be60ae666e058cbc59c11cb84d5cadb57f42f2f90602001610949565b6133476140b3565b6001600160a01b03811661338f5760405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b6044820152606401610866565b600154600160a81b900460ff16156133df5760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481d1c985b9cd9995c9c9959606a1b6044820152606401610866565b600080546001600160a01b038381166201000081810262010000600160b01b031990941693909317938490556001805460ff60a81b1916600160a81b1790556040805193909404909116825260208201527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9101610949565b600054610100900460ff166134735760005460ff1615613477565b303b155b6134da5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610866565b600054610100900460ff161580156134fc576000805461ffff19166101011790555b61350582610814565b8015613517576000805461ff00191690555b5050565b6040805160608101825260006020820181815292820152908152604051636392a51f60e01b81526001600160a01b0383811660048301526000918291861690636392a51f90602401604080518083038186803b15801561357a57600080fd5b505afa15801561358e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135b291906145d4565b60408051606081018252602081019384529081019190915290815295945050505050565b60035460408051622610c560e41b815290516060926000926101009091046001600160a01b03169163e73efc9b91849184916302610c50916004808301926020929190829003018186803b15801561362d57600080fd5b505afa158015613641573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061366591906145bc565b6040516001600160e01b031960e085901b1681526004810192909252602482015260440160006040518083038186803b1580156136a157600080fd5b505afa1580156136b5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526136dd9190810190614360565b90506000600360019054906101000a90046001600160a01b03166001600160a01b03166302610c506040518163ffffffff1660e01b815260040160206040518083038186803b15801561372f57600080fd5b505afa158015613743573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061376791906145bc565b841161377357836137f9565b600360019054906101000a90046001600160a01b03166001600160a01b03166302610c506040518163ffffffff1660e01b815260040160206040518083038186803b1580156137c157600080fd5b505afa1580156137d5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137f991906145bc565b905060006138078683614a00565b67ffffffffffffffff81111561382d57634e487b7160e01b600052604160045260246000fd5b60405190808252806020026020018201604052801561388b57816020015b613878604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b81526020019060019003908161384b5790505b509050855b82811015610ff6578381815181106138b857634e487b7160e01b600052603260045260246000fd5b60200260200101518288836138cd9190614a00565b815181106138eb57634e487b7160e01b600052603260045260246000fd5b60209081029190910101516001600160a01b0391821690526004548551911690635727a0f39086908490811061393157634e487b7160e01b600052603260045260246000fd5b60200260200101516040518263ffffffff1660e01b815260040161396491906001600160a01b0391909116815260200190565b60206040518083038186803b15801561397c57600080fd5b505afa158015613990573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139b49190614443565b15613b865760045484516001600160a01b0390911690636ed033f8908690849081106139f057634e487b7160e01b600052603260045260246000fd5b602002602001015160006040518363ffffffff1660e01b8152600401613a17929190614604565b60206040518083038186803b158015613a2f57600080fd5b505afa158015613a43573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a6791906145bc565b82613a728984614a00565b81518110613a9057634e487b7160e01b600052603260045260246000fd5b602090810291909101810151015260045484516001600160a01b0390911690636ed033f890869084908110613ad557634e487b7160e01b600052603260045260246000fd5b602002602001015160016040518363ffffffff1660e01b8152600401613afc929190614604565b60206040518083038186803b158015613b1457600080fd5b505afa158015613b28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b4c91906145bc565b82613b578984614a00565b81518110613b7557634e487b7160e01b600052603260045260246000fd5b602002602001015160400181815250505b80613b9081614a17565b915050613890565b606060008367ffffffffffffffff811115613bc357634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015613c2f57816020015b613c1c6040518060a0016040528060006001600160a01b03168152602001600081526020016000815260200160008152602001600081525090565b815260200190600190039081613be15790505b50905060005b8481101561131557858582818110613c5d57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190613c7291906142a2565b828281518110613c9257634e487b7160e01b600052603260045260246000fd5b60209081029190910101516001600160a01b0390911690526000868683818110613ccc57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190613ce191906142a2565b90506000816001600160a01b03166341bc7b1f6040518163ffffffff1660e01b815260040160606040518083038186803b158015613d1e57600080fd5b505afa158015613d32573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d569190614498565b5091505080848481518110613d7b57634e487b7160e01b600052603260045260246000fd5b6020908102919091010151608001526004546001600160a01b031663efc15251898986818110613dbb57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190613dd091906142a2565b886040518363ffffffff1660e01b8152600401613dee929190614604565b60206040518083038186803b158015613e0657600080fd5b505afa158015613e1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e3e91906145bc565b848481518110613e5e57634e487b7160e01b600052603260045260246000fd5b6020908102919091010151604001526004546001600160a01b031663bf46c0b4898986818110613e9e57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190613eb391906142a2565b88670de0b6b3a76400006040518463ffffffff1660e01b8152600401613edb9392919061462a565b60206040518083038186803b158015613ef357600080fd5b505afa158015613f07573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f2b91906145bc565b848481518110613f4b57634e487b7160e01b600052603260045260246000fd5b6020908102919091010151606001526004546001600160a01b031663270e13ef898986818110613f8b57634e487b7160e01b600052603260045260246000fd5b9050602002016020810190613fa091906142a2565b88670de0b6b3a76400006040518463ffffffff1660e01b8152600401613fc89392919061462a565b60206040518083038186803b158015613fe057600080fd5b505afa158015613ff4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061401891906145bc565b84848151811061403857634e487b7160e01b600052603260045260246000fd5b602002602001015160200181815250505050808061405590614a17565b915050613c35565b6140656140b3565b600580546001600160a01b0319166001600160a01b0383169081179091556040519081527f9f74cb0bcc60fb8fa09e2ee2a8a5da11b641195aa499c69210dd8c0ed9cf34e390602001610949565b6000546201000090046001600160a01b0316331461412b5760405162461bcd60e51b815260206004820152602f60248201527f4f6e6c792074686520636f6e7472616374206f776e6572206d6179207065726660448201526e37b936903a3434b99030b1ba34b7b760891b6064820152608401610866565b565b6040518060a0016040528060006001600160a01b03168152602001614177604051806040016040528060006001600160a01b0316815260200160006001600160a01b031681525090565b8152602001614199604051806040016040528060008152602001600081525090565b81526040805160a081018252600080825260208281018290529282018190526060820181905260808201529101905b81526020016141ea604051806040016040528060008152602001600081525090565b905290565b6040805161010081018252600060c0820181815260e083018290528252825160208082018552828252808401919091528351808501855282815290810191909152909182019081526020016000815260200160006141c8565b805161425381614a84565b919050565b60008083601f840112614269578081fd5b50813567ffffffffffffffff811115614280578182fd5b6020830191508360208260051b850101111561429b57600080fd5b9250929050565b6000602082840312156142b3578081fd5b81356142be81614a84565b9392505050565b6000602082840312156142d6578081fd5b81516142be81614a84565b6000806000604084860312156142f5578182fd5b833567ffffffffffffffff81111561430b578283fd5b61431786828701614258565b909450925050602084013561432b81614aa7565b809150509250925092565b60008060006040848603121561434a578283fd5b833567ffffffffffffffff81111561430b578384fd5b60006020808385031215614372578182fd5b825167ffffffffffffffff80821115614389578384fd5b818501915085601f83011261439c578384fd5b8151818111156143ae576143ae614a5e565b8060051b604051601f19603f830116810181811085821117156143d3576143d3614a5e565b604052828152858101935084860182860187018a10156143f1578788fd5b8795505b8386101561441a5761440681614248565b8552600195909501949386019386016143f5565b5098975050505050505050565b600060208284031215614438578081fd5b81356142be81614a99565b600060208284031215614454578081fd5b81516142be81614a99565b600060208284031215614470578081fd5b5035919050565b60008060408385031215614489578182fd5b50508035926020909101359150565b6000806000606084860312156144ac578081fd5b8351925060208401519150604084015190509250925092565b600080600080600060a086880312156144dc578283fd5b85519450602086015193506040860151925060608601516144fc81614a99565b608087015190925061450d81614a84565b809150509295509295909350565b6000806040838503121561452d578182fd5b825161453881614a84565b602084015190925061454981614a84565b809150509250929050565b60008060408385031215614566578182fd5b823561457181614a84565b9150602083013561454981614a84565b600060208284031215614592578081fd5b8151600381106142be578182fd5b6000602082840312156145b1578081fd5b81516142be81614aa7565b6000602082840312156145cd578081fd5b5051919050565b600080604083850312156145e6578182fd5b505080516020909101519092909150565b61460081614a74565b9052565b6001600160a01b03831681526040810161461d83614a74565b8260208301529392505050565b6001600160a01b03841681526060810161464384614a74565b602082019390935260400152919050565b6020808252825182820181905260009190848201906040850190845b818110156146955783516001600160a01b031683529284019291840191600101614670565b50909695505050505050565b6020808252825182820181905260009190848201906040850190845b81811015614695578351835292840192918401916001016146bd565b602080825282518282018190526000919060409081850190868401855b8281101561474357815180516001600160a01b0316855286810151878601528581015186860152606080820151908601526080908101519085015260a090930192908501906001016146f6565b5091979650505050505050565b602080825282518282018190526000919060409081850190868401855b8281101561474357815180516001600160a01b031685528681015187860152850151858501526060909301929085019060010161476d565b602080825282518282018190526000919060409081850190868401855b8281101561474357815180516001600160a01b0316855286810151878601528581015186860152606080820151908601526080808201519086015260a0908101519085015260c090930192908501906001016147c2565b8151805182526020908101519082015260408101610ffc565b60006101c082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160c083015260e083015160e08301526101008084015181840152506101208084015181840152506101408084015181840152506101608084015181840152506101808084015181840152506101a0808401516148d58285018215159052565b505092915050565b815180518252602090810151908201526101208101602083015151604083015260408301518051151560608401526020810151151560808401525060608301516003811061492d5761492d614a48565b60a0830152608083015161494460c08401826145f7565b5060a0830151805160e08401526020810151610100840152612e9a565b81516001600160a01b039081168252602080840151805183168285015281015182166040808501919091528401518051606085015290810151608084015261018083019190506060840151805160a0850152602081015160c0850152604081015160e0850152606081015115156101008501528160808201511661012085015250506080830151612e9a61014084018280518252602090810151910152565b600082821015614a1257614a12614a32565b500390565b6000600019821415614a2b57614a2b614a32565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b60028110610a1d57610a1d614a48565b6001600160a01b0381168114610a1d57600080fd5b8015158114610a1d57600080fd5b60028110610a1d57600080fdfea26469706673582212208d276e4f7c73b6eae6539870115e28649300eb6ba13b51ac6c98e6507d9042f164736f6c63430008040033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
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.