// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.4 <0.9.0; import '@defi-wonderland/isolmate/src/interfaces/tokens/IERC20.sol'; import '../IPoolManagerFactory.sol'; import '../periphery/IPriceOracleCorrections.sol'; /** @title PriceOracle contract @notice This contract allows you to get the price of different assets through WETH pools */ interface IPriceOracle is IPriceOracleCorrections { /*/////////////////////////////////////////////////////////////// STRUCTS //////////////////////////////////////////////////////////////*/ /** @notice A quote saved in a particular timestamp to use as cache @param quote The quote given from tokenA to tokenB @param timestamp The timestamp for when the cache was saved */ struct QuoteCache { uint256 quote; uint256 timestamp; // TODO not sure if it's more gas efficient to lower the uint type for this } /*/////////////////////////////////////////////////////////////// ERRORS //////////////////////////////////////////////////////////////*/ /** @notice Thrown when base amount overflows uint128 */ error PriceOracle_BaseAmountOverflow(); /** @notice Thrown when volatility in period is higher than accepted */ error PriceOracle_ExceededVolatility(); /*/////////////////////////////////////////////////////////////// VARIABLES //////////////////////////////////////////////////////////////*/ /** @notice Returns the WETH token @return _weth The WETH token */ function WETH() external view returns (IERC20 _weth); /** @notice Returns the volatility precision @return _volatilityPrecision The volatility precision */ function VOLATILITY_PRECISION() external view returns (uint256 _volatilityPrecision); /** @notice Returns the pool manager factory @return _poolManagerFactory The pool manager factory */ function POOL_MANAGER_FACTORY() external view returns (IPoolManagerFactory _poolManagerFactory); /*/////////////////////////////////////////////////////////////// LOGIC //////////////////////////////////////////////////////////////*/ /** @notice Returns true if a pair is supported on the oracle @param _tokenA The TokenA for the pair @param _tokenB The TokenB for the pair @return _isSupported True if the pair is supported on the oracle */ function isPairSupported(IERC20 _tokenA, IERC20 _tokenB) external view returns (bool _isSupported); /** @notice Returns the spot price of a given amount of tokenA quoted in tokenB @dev _baseAmount should not be greater than uint128.max @param _baseAmount The amount of tokenA to quote @param _tokenA The base token @param _tokenB The quote token @return _quoteAmount The quoted amount of tokenA in tokenB */ function quoteSpot( uint256 _baseAmount, IERC20 _tokenA, IERC20 _tokenB ) external view returns (uint256 _quoteAmount); /** @notice Returns the price of a given amount of tokenA quoted in tokenB using the cache if available @dev _baseAmount should not be greater than uint128.max @param _baseAmount The amount of tokenA to quote @param _tokenA Token to quote in tokenB @param _tokenB The quote token @param _period The period to quote @param _cacheExpiry The max time the cache is valid for use @return _quoteAmount The quoted amount of tokenA in tokenB */ function quotePeriodCache( uint256 _baseAmount, IERC20 _tokenA, IERC20 _tokenB, uint32 _period, uint24 _cacheExpiry ) external returns (uint256 _quoteAmount); /** @notice Returns the spot price of a given amount of tokenA quoted in tokenB reverting if it exceeds expected volatility @dev _baseAmount shouldn't be greater than uint128.max @dev check VOLATILITY_PRECISION for calculating the expected volatility @param _baseAmount The amount of tokenA to quote @param _tokenA Token to quote in tokenB @param _tokenB The quote token @param _period The period to quote @param _volatility The max volatility @param _cacheExpiry The max time the cache is valid for use @return _spotAmount The quoted amount of tokenA in tokenB */ function quoteSpotPeriodProtectedVolatilityCache( uint256 _baseAmount, IERC20 _tokenA, IERC20 _tokenB, uint32 _period, uint256 _volatility, uint24 _cacheExpiry ) external returns (uint256 _spotAmount); }