Verified contractPartialISC
FraxUsdcCurveLpDualOracle
Address0x2ad35cce2a690e0bf1e6dcac2f9175389f31d7f4
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.19
- Same code
1 more contract
Details
- Compiler
- solc 0.8.19+commit.7dd6d404
- Language
- solidity
- Optimization
- Yes, 1,000,000 runs
- EVM version
- london
- License
- ISC
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 17,273,483
- Creation transaction
- 0xcec95fb20d…13c13c4f17
24 files
- src/FraxUsdcCurveLpDualOracle.solmain16.44 KB
- lib/frax-standard-solidity/src/access-control/v1/Timelock2Step.sol5.62 KB
- lib/frax-standard-solidity/src/access-control/v1/interfaces/ITimelock2Step.sol577 B
- node_modules/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol668 B
- node_modules/@mean-finance/uniswap-v3-oracle/solidity/interfaces/IStaticOracle.sol8.19 KB
- node_modules/@openzeppelin/contracts/utils/introspection/ERC165.sol987 B
- node_modules/@openzeppelin/contracts/utils/introspection/ERC165Storage.sol1.38 KB
- node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol853 B
- node_modules/@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol4.04 KB
- src/DualOracleBase.sol3.61 KB
- src/abstracts/ChainlinkOracleWithMaxDelay.sol4.41 KB
- src/abstracts/CurvePoolVirtualPriceOracleWithMinMax.sol4.69 KB
- src/abstracts/EthUsdChainlinkOracleWithMaxDelay.sol4.72 KB
- src/abstracts/FraxUsdChainlinkOracleWithMaxDelay.sol4.78 KB
- src/abstracts/FraxUsdcUniswapV3SingleTwapOracle.sol4.15 KB
- src/abstracts/UniswapV3SingleTwapOracle.sol3.81 KB
- src/interfaces/IDualOracle.sol1.24 KB
- src/interfaces/IVirtualPriceStableSwap.sol170 B
- src/interfaces/oracles/abstracts/IChainlinkOracleWithMaxDelay.sol779 B
- src/interfaces/oracles/abstracts/ICurvePoolVirtualPriceOracleWithMinMax.sol942 B
- src/interfaces/oracles/abstracts/IEthUsdChainlinkOracleWithMaxDelay.sol817 B
- src/interfaces/oracles/abstracts/IFraxUsdChainlinkOracleWithMaxDelay.sol850 B
- src/interfaces/oracles/abstracts/IFraxUsdcUniswapV3SingleTwapOracle.sol841 B
- src/interfaces/oracles/abstracts/IUniswapV3SingleTwapOracle.sol761 B
src/FraxUsdcCurveLpDualOracle.sol
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ==================== FraxUsdcCurveLpDualOracle =====================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Author
// Drake Evans: https://github.com/DrakeEvans
// Reviewers
// Dennis: https://github.com/denett
// ====================================================================
import { Timelock2Step } from "frax-std/access-control/v1/Timelock2Step.sol";
import { ITimelock2Step } from "frax-std/access-control/v1/interfaces/ITimelock2Step.sol";
import {
CurvePoolVirtualPriceOracleWithMinMax,
ConstructorParams as CurvePoolVirtualPriceOracleWithMinMaxParams
} from "./abstracts/CurvePoolVirtualPriceOracleWithMinMax.sol";
import {
FraxUsdChainlinkOracleWithMaxDelay,
ConstructorParams as FraxUsdChainlinkOracleWithMaxDelayParams
} from "./abstracts/FraxUsdChainlinkOracleWithMaxDelay.sol";
import {
ChainlinkOracleWithMaxDelay,
ConstructorParams as ChainlinkOracleWithMaxDelayParams
} from "./abstracts/ChainlinkOracleWithMaxDelay.sol";
import {
FraxUsdcUniswapV3SingleTwapOracle,
ConstructorParams as FraxUsdcUniswapV3SingleTwapOracleParams
} from "./abstracts/FraxUsdcUniswapV3SingleTwapOracle.sol";
import {
EthUsdChainlinkOracleWithMaxDelay,
ConstructorParams as EthUsdChainlinkOracleWithMaxDelayParams
} from "./abstracts/EthUsdChainlinkOracleWithMaxDelay.sol";
import {
UniswapV3SingleTwapOracle,
ConstructorParams as UniswapV3SingleTwapOracleParams
} from "./abstracts/UniswapV3SingleTwapOracle.sol";
import { DualOracleBase, ConstructorParams as DualOracleBaseParams } from "./DualOracleBase.sol";
import { IDualOracle } from "interfaces/IDualOracle.sol";
struct ConstructorParams {
address timelockAddress;
address fraxErc20;
uint8 fraxErc20Decimals;
address usdcErc20;
uint8 usdcErc20Decimals;
address wethErc20;
uint8 wethErc20Decimals;
address fraxUsdcCurveLpErc20;
uint8 fraxUsdcCurveLpErc20Decimals;
// =
address baseToken0;
uint8 baseToken0Decimals;
address quoteToken0;
uint8 quoteToken0Decimals;
address baseToken1;
uint8 baseToken1Decimals;
address quoteToken1;
uint8 quoteToken1Decimals;
// =
address usdcUsdChainlinkFeedAddress;
uint256 usdUsdcChainlinkMaximumOracleDelay;
// =
address fraxUsdChainlinkFeedAddress;
uint256 fraxUsdMaximumOracleDelay;
// =
address curvePoolVirtualPriceAddress;
uint256 minimumCurvePoolVirtualPrice;
uint256 maximumCurvePoolVirtualPrice;
// =
address fraxUsdcUniswapV3PairAddress;
uint32 fraxUsdcTwapDuration;
address fraxUsdcTwapBaseToken;
address fraxUsdcTwapQuoteToken;
}
/// @title FraxUsdcCurveLpDualOracle
/// @author Drake Evans (Frax Finance) https://github.com/drakeevans
/// @notice An oracle for Frax/USDC Curve LP tokens
contract FraxUsdcCurveLpDualOracle is
Timelock2Step,
DualOracleBase,
CurvePoolVirtualPriceOracleWithMinMax,
FraxUsdChainlinkOracleWithMaxDelay,
ChainlinkOracleWithMaxDelay,
FraxUsdcUniswapV3SingleTwapOracle
{
uint8 public immutable FRAX_ERC20_DECIMALS;
uint256 public immutable FRAX_ERC20_PRECISION;
uint8 public immutable USDC_ERC20_DECIMALS;
uint256 public immutable USDC_ERC20_PRECISION;
uint8 public immutable FRAX_USDC_CURVE_POOL_LP_ERC20_DECIMALS;
uint256 public immutable FRAX_USDC_CURVE_POOL_LP_ERC20_PRECISION;
uint256 public immutable USDC_TO_FRAX_NORMALIZATION;
constructor(
ConstructorParams memory _params
)
Timelock2Step()
DualOracleBase(
DualOracleBaseParams({
baseToken0: _params.baseToken0,
baseToken0Decimals: _params.baseToken0Decimals,
quoteToken0: _params.quoteToken0,
quoteToken0Decimals: _params.quoteToken0Decimals,
baseToken1: _params.baseToken1,
baseToken1Decimals: _params.baseToken1Decimals,
quoteToken1: _params.quoteToken1,
quoteToken1Decimals: _params.quoteToken1Decimals
})
)
CurvePoolVirtualPriceOracleWithMinMax(
CurvePoolVirtualPriceOracleWithMinMaxParams({
curvePoolVirtualPriceAddress: _params.curvePoolVirtualPriceAddress,
minimumCurvePoolVirtualPrice: _params.minimumCurvePoolVirtualPrice,
maximumCurvePoolVirtualPrice: _params.maximumCurvePoolVirtualPrice
})
)
FraxUsdChainlinkOracleWithMaxDelay(
FraxUsdChainlinkOracleWithMaxDelayParams({
fraxUsdChainlinkFeedAddress: _params.fraxUsdChainlinkFeedAddress,
fraxUsdMaximumOracleDelay: _params.fraxUsdMaximumOracleDelay
})
)
ChainlinkOracleWithMaxDelay(
ChainlinkOracleWithMaxDelayParams({
chainlinkFeedAddress: _params.usdcUsdChainlinkFeedAddress,
maximumOracleDelay: _params.usdUsdcChainlinkMaximumOracleDelay
})
)
FraxUsdcUniswapV3SingleTwapOracle(
FraxUsdcUniswapV3SingleTwapOracleParams({
fraxUsdcUniswapV3PairAddress: _params.fraxUsdcUniswapV3PairAddress,
fraxUsdcTwapDuration: _params.fraxUsdcTwapDuration,
fraxUsdcTwapBaseToken: _params.fraxUsdcTwapBaseToken,
fraxUsdcTwapQuoteToken: _params.fraxUsdcTwapQuoteToken
})
)
{
_setTimelock({ _newTimelock: _params.timelockAddress });
_registerInterface({ interfaceId: type(IDualOracle).interfaceId });
_registerInterface({ interfaceId: type(ITimelock2Step).interfaceId });
FRAX_ERC20_DECIMALS = _params.fraxErc20Decimals;
FRAX_ERC20_PRECISION = 10 ** FRAX_ERC20_DECIMALS;
USDC_ERC20_DECIMALS = _params.usdcErc20Decimals;
USDC_ERC20_PRECISION = 10 ** USDC_ERC20_DECIMALS;
FRAX_USDC_CURVE_POOL_LP_ERC20_DECIMALS = _params.fraxUsdcCurveLpErc20Decimals;
FRAX_USDC_CURVE_POOL_LP_ERC20_PRECISION = 10 ** FRAX_USDC_CURVE_POOL_LP_ERC20_DECIMALS;
USDC_TO_FRAX_NORMALIZATION = FRAX_ERC20_PRECISION / USDC_ERC20_PRECISION;
}
function name() external pure returns (string memory) {
return "FraxUSDC Curve LP Dual Oracle w/ Min Max Bounds, Staleness Check";
}
// ====================================================================
// Configuration Setters
// ====================================================================
/// @notice The ```setMinimumCurvePoolVirtualPrice``` function is used to set the minimum virtual price
/// @param _newMinimum the new minimum virtual price
function setMinimumCurvePoolVirtualPrice(uint256 _newMinimum) external override {
_requireTimelock();
_setMinimumCurvePoolVirtualPrice({ _newMinimum: _newMinimum });
}
/// @notice The ```setMaximumCurvePoolVirtualPrice``` function is used to set the maximum virtual price
/// @param _newMaximum the new maximum virtual price
function setMaximumCurvePoolVirtualPrice(uint256 _newMaximum) external override {
_requireTimelock();
_setMaximumCurvePoolVirtualPrice({ _newMaximum: _newMaximum });
}
function setMaximumOracleDelay(uint256 _newMaxOracleDelay) external override {
_requireTimelock();
_setMaximumOracleDelay({ _newMaxOracleDelay: _newMaxOracleDelay });
}
function setMaximumFraxUsdOracleDelay(uint256 _newMaxOracleDelay) external override {
_requireTimelock();
_setMaximumFraxUsdOracleDelay({ _newMaxOracleDelay: _newMaxOracleDelay });
}
function setFraxUsdcTwapDuration(uint32 _newTwapDuration) external override {
_requireTimelock();
_setFraxUsdcTwapDuration({ _newTwapDuration: _newTwapDuration });
}
// ====================================================================
// Price Functions
// ====================================================================
/// @notice The ```getChainlinkUsdPerFrax``` function gets the Chainlink price of frax in usd units
/// @dev normalized to match precision of oracle
/// @return _isBadData Whether the Chainlink data is stale
/// @return _usdPerFrax
function getChainlinkUsdPerFrax() public view returns (bool _isBadData, uint256 _usdPerFrax) {
(bool _isBadDataChainlink, , uint256 _usdPerFraxRaw) = _getFraxUsdChainlinkPrice();
// Set return values
_isBadData = _isBadDataChainlink;
_usdPerFrax = (ORACLE_PRECISION * _usdPerFraxRaw) / CHAINLINK_FEED_PRECISION;
}
/// @notice The ```getFraxUsdcCurvePoolVirtualPrice``` function returns the normalized virtual price of the curve pool
/// @return _virtualPrice The normalized virtual price of the curve pool
function getFraxUsdcCurvePoolVirtualPrice() public view returns (uint256 _virtualPrice) {
uint256 _virtualPriceRaw = _getCurvePoolVirtualPrice();
// Set return values
_virtualPrice = (_virtualPriceRaw * (ORACLE_PRECISION / CURVE_POOL_VIRTUAL_PRICE_PRECISION));
}
/// @notice The ```getChainlinkUsdPerUsdc``` function gets the Chainlink price of usdc in usd units
/// @return _isBadData Whether the Chainlink data is stale or negative
/// @return _usdPerUsdc The normalized price of usdc in usd units
function getChainlinkUsdPerUsdc() public view returns (bool _isBadData, uint256 _usdPerUsdc) {
(bool _isBadDataChainlink, , uint256 _usdPerUsdcRaw) = _getChainlinkPrice();
// Set return values
_isBadData = _isBadDataChainlink;
_usdPerUsdc = (ORACLE_PRECISION * _usdPerUsdcRaw) / CHAINLINK_FEED_PRECISION;
}
/// @notice The ```getTwapFraxPerUsdc``` function gets the twap price of frax in usdc units
/// @return _fraxPerUsdc The normalized price of frax in usdc units
function getTwapFraxPerUsdc() public view returns (uint256 _fraxPerUsdc) {
// _getFraxUsdcUniswapV3Twap() is configured to return UsdcPerFrax
// Due to different decimals this number will be approximately 1e18 frax per 1e6 usdc and we want to return normalized values for comparisons
_fraxPerUsdc =
(ORACLE_PRECISION * _getFraxUsdcUniswapV3Twap()) /
(FRAX_USDC_TWAP_PRECISION * USDC_TO_FRAX_NORMALIZATION);
}
/// @notice The ```getPricesNormalized``` function returns the normalized prices in human readable form
/// @return _isBadDataNormal If the Chainlink oracle is stale
/// @return _priceLowNormal The normalized low price
/// @return _priceHighNormal The normalized high price
function getPricesNormalized()
external
view
returns (bool _isBadDataNormal, uint256 _priceLowNormal, uint256 _priceHighNormal)
{
(bool _isBadData, uint256 _priceLow, uint256 _priceHigh) = _getPrices();
_isBadDataNormal = _isBadData;
_priceLowNormal = NORMALIZATION_0 > 0
? _priceLow * 10 ** uint256(NORMALIZATION_0)
: _priceLow / 10 ** (uint256(-NORMALIZATION_0));
_priceHighNormal = NORMALIZATION_1 > 0
? _priceHigh * 10 ** uint256(NORMALIZATION_1)
: _priceHigh / 10 ** (uint256(-NORMALIZATION_1));
}
/// @notice The ```calculatePrices``` function calculates the normalized prices in a pure function
/// @param _isBadDataFraxUsdChainlink True if the FraxUsdChainlink returns stale data
/// @param _usdPerFraxChainlink The price of frax in usd units
/// @param _underlyingPerLp The amount of underlying per lp token from the curve pool
/// @param _isBadDataUsdcUsdChainlink True if the UsdcUsdChainlink returns stale data
/// @param _usdPerUsdcChainlink The price of usdc in usd units
/// @param _fraxPerUsdcTwap The price of usdc in frax units
/// @return _isBadData True if any of the oracles return stale data
/// @return _priceLow The normalized low price
/// @return _priceHigh The normalized high price
function calculatePrices(
bool _isBadDataFraxUsdChainlink,
uint256 _usdPerFraxChainlink,
uint256 _underlyingPerLp,
bool _isBadDataUsdcUsdChainlink,
uint256 _usdPerUsdcChainlink,
uint256 _fraxPerUsdcTwap
) external pure returns (bool _isBadData, uint256 _priceLow, uint256 _priceHigh) {
return
_calculatePrices({
_isBadDataFraxUsdChainlink: _isBadDataFraxUsdChainlink,
_usdPerFraxChainlink: _usdPerFraxChainlink,
_underlyingPerLp: _underlyingPerLp,
_isBadDataUsdcUsdChainlink: _isBadDataUsdcUsdChainlink,
_usdPerUsdcChainlink: _usdPerUsdcChainlink,
_fraxPerUsdcTwap: _fraxPerUsdcTwap
});
}
function _calculatePrices(
bool _isBadDataFraxUsdChainlink,
uint256 _usdPerFraxChainlink,
uint256 _underlyingPerLp,
bool _isBadDataUsdcUsdChainlink,
uint256 _usdPerUsdcChainlink,
uint256 _fraxPerUsdcTwap
) internal pure returns (bool _isBadData, uint256 _priceLow, uint256 _priceHigh) {
// Usdc Chainlink Price in frax units
uint256 _fraxPerUsdcChainlink = (ORACLE_PRECISION * _usdPerUsdcChainlink) / _usdPerFraxChainlink;
// We know 1 FRAX = 1 FRAX so we check if the values are less than 1
// We want to return the value which represents the least valuable collateral
uint256 _fraxPerUnderlying1 = _fraxPerUsdcTwap < ORACLE_PRECISION ? _fraxPerUsdcTwap : ORACLE_PRECISION;
uint256 _fraxPerUnderlying2 = _fraxPerUsdcChainlink < ORACLE_PRECISION
? _fraxPerUsdcChainlink
: ORACLE_PRECISION;
// Multiply by virtualPrice
uint256 _fraxPerLp1 = (_fraxPerUnderlying1 * _underlyingPerLp) / ORACLE_PRECISION;
uint256 _fraxPerLp2 = (_fraxPerUnderlying2 * _underlyingPerLp) / ORACLE_PRECISION;
// Flip values so that they are in the form of collateral/asset
uint256 _lpPerFrax1 = (ORACLE_PRECISION * ORACLE_PRECISION) / _fraxPerLp1;
uint256 _lpPerFrax2 = (ORACLE_PRECISION * ORACLE_PRECISION) / _fraxPerLp2;
// Set return values
_isBadData = _isBadDataUsdcUsdChainlink || _isBadDataFraxUsdChainlink;
_priceLow = _lpPerFrax1 < _lpPerFrax2 ? _lpPerFrax1 : _lpPerFrax2;
_priceHigh = _lpPerFrax1 > _lpPerFrax2 ? _lpPerFrax1 : _lpPerFrax2;
}
function _getPrices() internal view returns (bool _isBadData, uint256 _priceLow, uint256 _priceHigh) {
// These values have been normalized to ORACLE_PRECISION
(bool _isBadDataFraxUsdChainlink, uint256 _usdPerFraxChainlink) = getChainlinkUsdPerFrax();
uint256 _underlyingPerLp = getFraxUsdcCurvePoolVirtualPrice();
(bool _isBadDataUsdcUsdChainlink, uint256 _usdPerUsdcChainlink) = getChainlinkUsdPerUsdc();
uint256 _fraxPerUsdcTwap = getTwapFraxPerUsdc();
// Set return values
(_isBadData, _priceLow, _priceHigh) = _calculatePrices({
_isBadDataFraxUsdChainlink: _isBadDataFraxUsdChainlink,
_usdPerFraxChainlink: _usdPerFraxChainlink,
_underlyingPerLp: _underlyingPerLp,
_isBadDataUsdcUsdChainlink: _isBadDataUsdcUsdChainlink,
_usdPerUsdcChainlink: _usdPerUsdcChainlink,
_fraxPerUsdcTwap: _fraxPerUsdcTwap
});
}
/// @notice The ```getPrices``` function is intended to return two prices from different oracles
/// @return _isBadData is true when data is stale or otherwise bad
/// @return _priceLow is the lower of the two prices
/// @return _priceHigh is the higher of the two prices
function getPrices() external view returns (bool _isBadData, uint256 _priceLow, uint256 _priceHigh) {
return _getPrices();
}
}
lib/frax-standard-solidity/src/access-control/v1/Timelock2Step.sol
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ========================== Timelock2Step ===========================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Primary Author
// Drake Evans: https://github.com/DrakeEvans
// Reviewers
// Dennis: https://github.com/denett
// ====================================================================
/// @title Timelock2Step
/// @author Drake Evans (Frax Finance) https://github.com/drakeevans
/// @dev Inspired by the OpenZeppelin's Ownable2Step contract
/// @notice An abstract contract which contains 2-step transfer and renounce logic for a timelock address
abstract contract Timelock2Step {
/// @notice The pending timelock address
address public pendingTimelockAddress;
/// @notice The current timelock address
address public timelockAddress;
constructor() {
timelockAddress = msg.sender;
}
/// @notice Emitted when timelock is transferred
error OnlyTimelock();
/// @notice Emitted when pending timelock is transferred
error OnlyPendingTimelock();
/// @notice The ```TimelockTransferStarted``` event is emitted when the timelock transfer is initiated
/// @param previousTimelock The address of the previous timelock
/// @param newTimelock The address of the new timelock
event TimelockTransferStarted(address indexed previousTimelock, address indexed newTimelock);
/// @notice The ```TimelockTransferred``` event is emitted when the timelock transfer is completed
/// @param previousTimelock The address of the previous timelock
/// @param newTimelock The address of the new timelock
event TimelockTransferred(address indexed previousTimelock, address indexed newTimelock);
/// @notice The ```_isSenderTimelock``` function checks if msg.sender is current timelock address
/// @return Whether or not msg.sender is current timelock address
function _isSenderTimelock() internal view returns (bool) {
return msg.sender == timelockAddress;
}
/// @notice The ```_requireTimelock``` function reverts if msg.sender is not current timelock address
function _requireTimelock() internal view {
if (msg.sender != timelockAddress) revert OnlyTimelock();
}
/// @notice The ```_isSenderPendingTimelock``` function checks if msg.sender is pending timelock address
/// @return Whether or not msg.sender is pending timelock address
function _isSenderPendingTimelock() internal view returns (bool) {
return msg.sender == pendingTimelockAddress;
}
/// @notice The ```_requirePendingTimelock``` function reverts if msg.sender is not pending timelock address
function _requirePendingTimelock() internal view {
if (msg.sender != pendingTimelockAddress) revert OnlyPendingTimelock();
}
/// @notice The ```_transferTimelock``` function initiates the timelock transfer
/// @dev This function is to be implemented by a public function
/// @param _newTimelock The address of the nominated (pending) timelock
function _transferTimelock(address _newTimelock) internal {
pendingTimelockAddress = _newTimelock;
emit TimelockTransferStarted(timelockAddress, _newTimelock);
}
/// @notice The ```_acceptTransferTimelock``` function completes the timelock transfer
/// @dev This function is to be implemented by a public function
function _acceptTransferTimelock() internal {
pendingTimelockAddress = address(0);
_setTimelock(msg.sender);
}
/// @notice The ```_setTimelock``` function sets the timelock address
/// @dev This function is to be implemented by a public function
/// @param _newTimelock The address of the new timelock
function _setTimelock(address _newTimelock) internal {
emit TimelockTransferred(timelockAddress, _newTimelock);
timelockAddress = _newTimelock;
}
/// @notice The ```transferTimelock``` function initiates the timelock transfer
/// @dev Must be called by the current timelock
/// @param _newTimelock The address of the nominated (pending) timelock
function transferTimelock(address _newTimelock) external virtual {
_requireTimelock();
_transferTimelock(_newTimelock);
}
/// @notice The ```acceptTransferTimelock``` function completes the timelock transfer
/// @dev Must be called by the pending timelock
function acceptTransferTimelock() external virtual {
_requirePendingTimelock();
_acceptTransferTimelock();
}
/// @notice The ```renounceTimelock``` function renounces the timelock after setting pending timelock to current timelock
/// @dev Pending timelock must be set to current timelock before renouncing, creating a 2-step renounce process
function renounceTimelock() external virtual {
_requireTimelock();
_requirePendingTimelock();
_transferTimelock(address(0));
_setTimelock(address(0));
}
}
lib/frax-standard-solidity/src/access-control/v1/interfaces/ITimelock2Step.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;
interface ITimelock2Step {
event TimelockTransferStarted(address indexed previousTimelock, address indexed newTimelock);
event TimelockTransferred(address indexed previousTimelock, address indexed newTimelock);
function acceptTransferTimelock() external;
function pendingTimelockAddress() external view returns (address);
function renounceTimelock() external;
function timelockAddress() external view returns (address);
function transferTimelock(address _newTimelock) external;
}
node_modules/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
node_modules/@mean-finance/uniswap-v3-oracle/solidity/interfaces/IStaticOracle.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.6 <0.9.0;
import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol';
/// @title Uniswap V3 Static Oracle
/// @notice Oracle contract for calculating price quoting against Uniswap V3
interface IStaticOracle {
/// @notice Returns the address of the Uniswap V3 factory
/// @dev This value is assigned during deployment and cannot be changed
/// @return The address of the Uniswap V3 factory
function UNISWAP_V3_FACTORY() external view returns (IUniswapV3Factory);
/// @notice Returns how many observations are needed per minute in Uniswap V3 oracles, on the deployed chain
/// @dev This value is assigned during deployment and cannot be changed
/// @return Number of observation that are needed per minute
function CARDINALITY_PER_MINUTE() external view returns (uint8);
/// @notice Returns all supported fee tiers
/// @return The supported fee tiers
function supportedFeeTiers() external view returns (uint24[] memory);
/// @notice Returns whether a specific pair can be supported by the oracle
/// @dev The pair can be provided in tokenA/tokenB or tokenB/tokenA order
/// @return Whether the given pair can be supported by the oracle
function isPairSupported(address tokenA, address tokenB) external view returns (bool);
/// @notice Returns all existing pools for the given pair
/// @dev The pair can be provided in tokenA/tokenB or tokenB/tokenA order
/// @return All existing pools for the given pair
function getAllPoolsForPair(address tokenA, address tokenB) external view returns (address[] memory);
/// @notice Returns a quote, based on the given tokens and amount, by querying all of the pair's pools
/// @dev If some pools are not configured correctly for the given period, then they will be ignored
/// @dev Will revert if there are no pools available/configured for the pair and period combination
/// @param baseAmount Amount of token to be converted
/// @param baseToken Address of an ERC20 token contract used as the baseAmount denomination
/// @param quoteToken Address of an ERC20 token contract used as the quoteAmount denomination
/// @param period Number of seconds from which to calculate the TWAP
/// @return quoteAmount Amount of quoteToken received for baseAmount of baseToken
/// @return queriedPools The pools that were queried to calculate the quote
function quoteAllAvailablePoolsWithTimePeriod(
uint128 baseAmount,
address baseToken,
address quoteToken,
uint32 period
) external view returns (uint256 quoteAmount, address[] memory queriedPools);
/// @notice Returns a quote, based on the given tokens and amount, by querying only the specified fee tiers
/// @dev Will revert if the pair does not have a pool for one of the given fee tiers, or if one of the pools
/// is not prepared/configured correctly for the given period
/// @param baseAmount Amount of token to be converted
/// @param baseToken Address of an ERC20 token contract used as the baseAmount denomination
/// @param quoteToken Address of an ERC20 token contract used as the quoteAmount denomination
/// @param feeTiers The fee tiers to consider when calculating the quote
/// @param period Number of seconds from which to calculate the TWAP
/// @return quoteAmount Amount of quoteToken received for baseAmount of baseToken
/// @return queriedPools The pools that were queried to calculate the quote
function quoteSpecificFeeTiersWithTimePeriod(
uint128 baseAmount,
address baseToken,
address quoteToken,
uint24[] calldata feeTiers,
uint32 period
) external view returns (uint256 quoteAmount, address[] memory queriedPools);
/// @notice Returns a quote, based on the given tokens and amount, by querying only the specified pools
/// @dev Will revert if one of the pools is not prepared/configured correctly for the given period
/// @param baseAmount Amount of token to be converted
/// @param baseToken Address of an ERC20 token contract used as the baseAmount denomination
/// @param quoteToken Address of an ERC20 token contract used as the quoteAmount denomination
/// @param pools The pools to consider when calculating the quote
/// @param period Number of seconds from which to calculate the TWAP
/// @return quoteAmount Amount of quoteToken received for baseAmount of baseToken
function quoteSpecificPoolsWithTimePeriod(
uint128 baseAmount,
address baseToken,
address quoteToken,
address[] calldata pools,
uint32 period
) external view returns (uint256 quoteAmount);
/// @notice Will initialize all existing pools for the given pair, so that they can be queried with the given period in the future
/// @dev Will revert if there are no pools available for the pair and period combination
/// @param tokenA One of the pair's tokens
/// @param tokenB The other of the pair's tokens
/// @param period The period that will be guaranteed when quoting
/// @return preparedPools The pools that were prepared
function prepareAllAvailablePoolsWithTimePeriod(
address tokenA,
address tokenB,
uint32 period
) external returns (address[] memory preparedPools);
/// @notice Will initialize the pair's pools with the specified fee tiers, so that they can be queried with the given period in the future
/// @dev Will revert if the pair does not have a pool for a given fee tier
/// @param tokenA One of the pair's tokens
/// @param tokenB The other of the pair's tokens
/// @param feeTiers The fee tiers to consider when searching for the pair's pools
/// @param period The period that will be guaranteed when quoting
/// @return preparedPools The pools that were prepared
function prepareSpecificFeeTiersWithTimePeriod(
address tokenA,
address tokenB,
uint24[] calldata feeTiers,
uint32 period
) external returns (address[] memory preparedPools);
/// @notice Will initialize all given pools, so that they can be queried with the given period in the future
/// @param pools The pools to initialize
/// @param period The period that will be guaranteed when quoting
function prepareSpecificPoolsWithTimePeriod(address[] calldata pools, uint32 period) external;
/// @notice Will increase observations for all existing pools for the given pair, so they start accruing information for twap calculations
/// @dev Will revert if there are no pools available for the pair and period combination
/// @param tokenA One of the pair's tokens
/// @param tokenB The other of the pair's tokens
/// @param cardinality The cardinality that will be guaranteed when quoting
/// @return preparedPools The pools that were prepared
function prepareAllAvailablePoolsWithCardinality(
address tokenA,
address tokenB,
uint16 cardinality
) external returns (address[] memory preparedPools);
/// @notice Will increase the pair's pools with the specified fee tiers observations, so they start accruing information for twap calculations
/// @dev Will revert if the pair does not have a pool for a given fee tier
/// @param tokenA One of the pair's tokens
/// @param tokenB The other of the pair's tokens
/// @param feeTiers The fee tiers to consider when searching for the pair's pools
/// @param cardinality The cardinality that will be guaranteed when quoting
/// @return preparedPools The pools that were prepared
function prepareSpecificFeeTiersWithCardinality(
address tokenA,
address tokenB,
uint24[] calldata feeTiers,
uint16 cardinality
) external returns (address[] memory preparedPools);
/// @notice Will increase all given pools observations, so they start accruing information for twap calculations
/// @param pools The pools to initialize
/// @param cardinality The cardinality that will be guaranteed when quoting
function prepareSpecificPoolsWithCardinality(address[] calldata pools, uint16 cardinality) external;
/// @notice Adds support for a new fee tier
/// @dev Will revert if the given tier is invalid, or already supported
/// @param feeTier The new fee tier to add
function addNewFeeTier(uint24 feeTier) external;
}
node_modules/@openzeppelin/contracts/utils/introspection/ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
node_modules/@openzeppelin/contracts/utils/introspection/ERC165Storage.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165Storage.sol)
pragma solidity ^0.8.0;
import "./ERC165.sol";
/**
* @dev Storage based implementation of the {IERC165} interface.
*
* Contracts may inherit from this and call {_registerInterface} to declare
* their support of an interface.
*/
abstract contract ERC165Storage is ERC165 {
/**
* @dev Mapping of interface ids to whether or not it's supported.
*/
mapping(bytes4 => bool) private _supportedInterfaces;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return super.supportsInterface(interfaceId) || _supportedInterfaces[interfaceId];
}
/**
* @dev Registers the contract as an implementer of the interface defined by
* `interfaceId`. Support of the actual ERC165 interface is automatic and
* registering its interface id is not required.
*
* See {IERC165-supportsInterface}.
*
* Requirements:
*
* - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
*/
function _registerInterface(bytes4 interfaceId) internal virtual {
require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
_supportedInterfaces[interfaceId] = true;
}
}
node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
node_modules/@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title The interface for the Uniswap V3 Factory
/// @notice The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees
interface IUniswapV3Factory {
/// @notice Emitted when the owner of the factory is changed
/// @param oldOwner The owner before the owner was changed
/// @param newOwner The owner after the owner was changed
event OwnerChanged(address indexed oldOwner, address indexed newOwner);
/// @notice Emitted when a pool is created
/// @param token0 The first token of the pool by address sort order
/// @param token1 The second token of the pool by address sort order
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks
/// @param pool The address of the created pool
event PoolCreated(
address indexed token0,
address indexed token1,
uint24 indexed fee,
int24 tickSpacing,
address pool
);
/// @notice Emitted when a new fee amount is enabled for pool creation via the factory
/// @param fee The enabled fee, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks for pools created with the given fee
event FeeAmountEnabled(uint24 indexed fee, int24 indexed tickSpacing);
/// @notice Returns the current owner of the factory
/// @dev Can be changed by the current owner via setOwner
/// @return The address of the factory owner
function owner() external view returns (address);
/// @notice Returns the tick spacing for a given fee amount, if enabled, or 0 if not enabled
/// @dev A fee amount can never be removed, so this value should be hard coded or cached in the calling context
/// @param fee The enabled fee, denominated in hundredths of a bip. Returns 0 in case of unenabled fee
/// @return The tick spacing
function feeAmountTickSpacing(uint24 fee) external view returns (int24);
/// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist
/// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
/// @param tokenA The contract address of either token0 or token1
/// @param tokenB The contract address of the other token
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @return pool The pool address
function getPool(
address tokenA,
address tokenB,
uint24 fee
) external view returns (address pool);
/// @notice Creates a pool for the given two tokens and fee
/// @param tokenA One of the two tokens in the desired pool
/// @param tokenB The other of the two tokens in the desired pool
/// @param fee The desired fee for the pool
/// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved
/// from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments
/// are invalid.
/// @return pool The address of the newly created pool
function createPool(
address tokenA,
address tokenB,
uint24 fee
) external returns (address pool);
/// @notice Updates the owner of the factory
/// @dev Must be called by the current owner
/// @param _owner The new owner of the factory
function setOwner(address _owner) external;
/// @notice Enables a fee amount with the given tickSpacing
/// @dev Fee amounts may never be removed once enabled
/// @param fee The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6)
/// @param tickSpacing The spacing between ticks to be enforced for all pools created with the given fee amount
function enableFeeAmount(uint24 fee, int24 tickSpacing) external;
}
src/DualOracleBase.sol
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ========================== DualOracleBase ==========================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Author
// Drake Evans: https://github.com/DrakeEvans
// ====================================================================
import "interfaces/IDualOracle.sol";
struct ConstructorParams {
address baseToken0;
uint8 baseToken0Decimals;
address quoteToken0;
uint8 quoteToken0Decimals;
address baseToken1;
uint8 baseToken1Decimals;
address quoteToken1;
uint8 quoteToken1Decimals;
}
/// @title DualOracleBase
/// @author Drake Evans (Frax Finance) https://github.com/drakeevans
/// @notice Base Contract for Frax Dual Oracles
abstract contract DualOracleBase is IDualOracle {
/// @notice The precision of the oracle
uint256 public constant ORACLE_PRECISION = 1e18;
/// @notice The first quote token
address public immutable QUOTE_TOKEN_0;
/// @notice The first quote token decimals
uint256 public immutable QUOTE_TOKEN_0_DECIMALS;
/// @notice The second quote token
address public immutable QUOTE_TOKEN_1;
/// @notice The second quote token decimals
uint256 public immutable QUOTE_TOKEN_1_DECIMALS;
/// @notice The first base token
address public immutable BASE_TOKEN_0;
/// @notice The first base token decimals
uint256 public immutable BASE_TOKEN_0_DECIMALS;
/// @notice The second base token
address public immutable BASE_TOKEN_1;
/// @notice The second base token decimals
uint256 public immutable BASE_TOKEN_1_DECIMALS;
/// @notice The first normalization factor which accounts for different decimals across ERC20s
/// @dev Normalization = quoteTokenDecimals - baseTokenDecimals
int256 public immutable NORMALIZATION_0;
/// @notice The second normalization factor which accounts for different decimals across ERC20s
/// @dev Normalization = quoteTokenDecimals - baseTokenDecimals
int256 public immutable NORMALIZATION_1;
constructor(ConstructorParams memory _params) {
QUOTE_TOKEN_0 = _params.quoteToken0;
QUOTE_TOKEN_0_DECIMALS = _params.quoteToken0Decimals;
QUOTE_TOKEN_1 = _params.quoteToken1;
QUOTE_TOKEN_1_DECIMALS = _params.quoteToken1Decimals;
BASE_TOKEN_0 = _params.baseToken0;
BASE_TOKEN_0_DECIMALS = _params.baseToken0Decimals;
BASE_TOKEN_1 = _params.baseToken1;
BASE_TOKEN_1_DECIMALS = _params.baseToken1Decimals;
NORMALIZATION_0 = int256(QUOTE_TOKEN_0_DECIMALS) - int256(BASE_TOKEN_0_DECIMALS);
NORMALIZATION_1 = int256(QUOTE_TOKEN_1_DECIMALS) - int256(BASE_TOKEN_1_DECIMALS);
}
// ====================================================================
// View Helpers
// ====================================================================
function decimals() external pure returns (uint8) {
return 18;
}
}
src/abstracts/ChainlinkOracleWithMaxDelay.sol
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// =================== ChainlinkOracleWithMaxDelay ====================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Author
// Drake Evans: https://github.com/DrakeEvans
// Reviewers
// Dennis: https://github.com/denett
// ====================================================================
import { AggregatorV3Interface } from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import { ERC165Storage } from "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
import { IChainlinkOracleWithMaxDelay } from "interfaces/oracles/abstracts/IChainlinkOracleWithMaxDelay.sol";
struct ConstructorParams {
address chainlinkFeedAddress;
uint256 maximumOracleDelay;
}
/// @title ChainlinkOracleWithMaxDelay
/// @author Drake Evans (Frax Finance) https://github.com/drakeevans
/// @notice An abstract oracle for getting prices from Chainlink
abstract contract ChainlinkOracleWithMaxDelay is ERC165Storage, IChainlinkOracleWithMaxDelay {
/// @notice Chainlink aggregator
address public immutable CHAINLINK_FEED_ADDRESS;
/// @notice Decimals of ETH/USD chainlink feed
uint8 public immutable CHAINLINK_FEED_DECIMALS;
/// @notice Precision of ETH/USD chainlink feed
uint256 public immutable CHAINLINK_FEED_PRECISION;
/// @notice Maximum delay of Chainlink data, after which it is considered stale
uint256 public maximumOracleDelay;
constructor(ConstructorParams memory _params) {
_registerInterface({ interfaceId: type(IChainlinkOracleWithMaxDelay).interfaceId });
CHAINLINK_FEED_ADDRESS = _params.chainlinkFeedAddress;
CHAINLINK_FEED_DECIMALS = AggregatorV3Interface(CHAINLINK_FEED_ADDRESS).decimals();
CHAINLINK_FEED_PRECISION = 10 ** uint256(CHAINLINK_FEED_DECIMALS);
maximumOracleDelay = _params.maximumOracleDelay;
}
/// @notice The ```SetMaximumOracleDelay``` event is emitted when the max oracle delay is set
/// @param oldMaxOracleDelay The old max oracle delay
/// @param newMaxOracleDelay The new max oracle delay
event SetMaximumOracleDelay(uint256 oldMaxOracleDelay, uint256 newMaxOracleDelay);
/// @notice The ```_setMaximumOracleDelay``` function sets the max oracle delay to determine if Chainlink data is stale
/// @param _newMaxOracleDelay The new max oracle delay
function _setMaximumOracleDelay(uint256 _newMaxOracleDelay) internal {
emit SetMaximumOracleDelay({ oldMaxOracleDelay: maximumOracleDelay, newMaxOracleDelay: _newMaxOracleDelay });
maximumOracleDelay = _newMaxOracleDelay;
}
function setMaximumOracleDelay(uint256 _newMaxOracleDelay) external virtual;
function _getChainlinkPrice() internal view returns (bool _isBadData, uint256 _updatedAt, uint256 _price) {
(, int256 _answer, , uint256 _chainlinkUpdatedAt, ) = AggregatorV3Interface(CHAINLINK_FEED_ADDRESS)
.latestRoundData();
// If data is stale or negative, set bad data to true and return
_isBadData = _answer <= 0 || ((block.timestamp - _chainlinkUpdatedAt) > maximumOracleDelay);
_updatedAt = _chainlinkUpdatedAt;
_price = uint256(_answer);
}
/// @notice The ```getChainlinkPrice``` function returns the chainlink price and the timestamp of the last update
/// @dev Uses the same prevision as the chainlink feed, virtual so it can be overridden
/// @return _isBadData True if the data is stale or negative
/// @return _updatedAt The timestamp of the last update
/// @return _price The price
function getChainlinkPrice() external view virtual returns (bool _isBadData, uint256 _updatedAt, uint256 _price) {
return _getChainlinkPrice();
}
}
src/abstracts/CurvePoolVirtualPriceOracleWithMinMax.sol
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ============== CurvePoolVirtualPriceOracleWithMinMax ===============
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Author
// Drake Evans: https://github.com/DrakeEvans
// Reviewers
// Dennis: https://github.com/denett
// ====================================================================
import { ERC165Storage } from "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
import {
ICurvePoolVirtualPriceOracleWithMinMax
} from "interfaces/oracles/abstracts/ICurvePoolVirtualPriceOracleWithMinMax.sol";
import { IVirtualPriceStableSwap } from "interfaces/IVirtualPriceStableSwap.sol";
struct ConstructorParams {
address curvePoolVirtualPriceAddress;
uint256 minimumCurvePoolVirtualPrice;
uint256 maximumCurvePoolVirtualPrice;
}
/// @title CurvePoolVirtualPriceOracleWithMinMax
/// @author Drake Evans (Frax Finance) https://github.com/drakeevans
/// @notice An oracle for getting curve LP virtual price
abstract contract CurvePoolVirtualPriceOracleWithMinMax is ERC165Storage, ICurvePoolVirtualPriceOracleWithMinMax {
/// @notice Curve pool, source of virtual price
address public immutable CURVE_POOL_VIRTUAL_PRICE_ADDRESS;
/// @notice Precision of Curve pool get_virtual_price()
uint256 public constant CURVE_POOL_VIRTUAL_PRICE_PRECISION = 1e18;
/// @notice Minimum virtual price of Curve pool allowed
uint256 public minimumCurvePoolVirtualPrice;
/// @notice Maximum virtual price of Curve pool allowed
uint256 public maximumCurvePoolVirtualPrice;
constructor(ConstructorParams memory _params) {
_registerInterface({ interfaceId: type(ICurvePoolVirtualPriceOracleWithMinMax).interfaceId });
// Curve pool config
CURVE_POOL_VIRTUAL_PRICE_ADDRESS = _params.curvePoolVirtualPriceAddress;
minimumCurvePoolVirtualPrice = _params.minimumCurvePoolVirtualPrice;
maximumCurvePoolVirtualPrice = _params.maximumCurvePoolVirtualPrice;
}
/// @notice The ```_setMinimumCurvePoolVirtualPrice``` function is called to set the minimum virtual price
/// @dev Contains no access control
/// @param _newMinimum The new minimum price
function _setMinimumCurvePoolVirtualPrice(uint256 _newMinimum) internal {
emit SetMinimumCurvePoolVirtualPrice({ oldMinimum: minimumCurvePoolVirtualPrice, newMinimum: _newMinimum });
minimumCurvePoolVirtualPrice = _newMinimum;
}
function setMinimumCurvePoolVirtualPrice(uint256 _newMinimum) external virtual;
/// @notice The ```_setMaximumCurvePoolVirtualPrice``` function is called to set the maximum virtual price
/// @dev Contains no access control
/// @param _newMaximum The new maximum price
function _setMaximumCurvePoolVirtualPrice(uint256 _newMaximum) internal {
emit SetMaximumCurvePoolVirtualPrice({ oldMaximum: maximumCurvePoolVirtualPrice, newMaximum: _newMaximum });
maximumCurvePoolVirtualPrice = _newMaximum;
}
function setMaximumCurvePoolVirtualPrice(uint256 _newMaximum) external virtual;
/// @notice The ```_getCurvePoolVirtualPrice``` function is called to get the virtual price
/// @return _virtualPrice The virtual price
function _getCurvePoolVirtualPrice() internal view returns (uint256 _virtualPrice) {
_virtualPrice = IVirtualPriceStableSwap(CURVE_POOL_VIRTUAL_PRICE_ADDRESS).get_virtual_price();
// Cap the price at current max
_virtualPrice = _virtualPrice > maximumCurvePoolVirtualPrice ? maximumCurvePoolVirtualPrice : _virtualPrice;
// Price should never be below 1
_virtualPrice = _virtualPrice < minimumCurvePoolVirtualPrice ? minimumCurvePoolVirtualPrice : _virtualPrice;
}
/// @notice The ```getCurvePoolVirtualPrice``` function is called to get the virtual price
/// @return _virtualPrice The virtual price
function getCurvePoolVirtualPrice() external view virtual returns (uint256 _virtualPrice) {
return _getCurvePoolVirtualPrice();
}
}
src/abstracts/EthUsdChainlinkOracleWithMaxDelay.sol
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ================ EthUsdChainlinkOracleWithMaxDelay =================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Author
// Drake Evans: https://github.com/DrakeEvans
// Reviewers
// Dennis: https://github.com/denett
// ====================================================================
import { AggregatorV3Interface } from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import { ERC165Storage } from "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
import {
IEthUsdChainlinkOracleWithMaxDelay
} from "interfaces/oracles/abstracts/IEthUsdChainlinkOracleWithMaxDelay.sol";
struct ConstructorParams {
address ethUsdChainlinkFeedAddress;
uint256 maxEthUsdOracleDelay;
}
/// @title EthUsdChainlinkOracleWithMaxDelay
/// @author Drake Evans (Frax Finance) https://github.com/drakeevans
/// @notice An abstract oracle for getting eth/usd prices from Chainlink
abstract contract EthUsdChainlinkOracleWithMaxDelay is ERC165Storage, IEthUsdChainlinkOracleWithMaxDelay {
/// @notice Chainlink aggregator
address public immutable ETH_USD_CHAINLINK_FEED_ADDRESS;
/// @notice Decimals of ETH/USD chainlink feed
uint8 public immutable ETH_USD_CHAINLINK_FEED_DECIMALS;
/// @notice Precision of ETH/USD chainlink feed
uint256 public immutable ETH_USD_CHAINLINK_FEED_PRECISION;
/// @notice Maximum delay of Chainlink data, after which it is considered stale
uint256 public maximumEthUsdOracleDelay;
constructor(ConstructorParams memory _params) {
_registerInterface({ interfaceId: type(IEthUsdChainlinkOracleWithMaxDelay).interfaceId });
ETH_USD_CHAINLINK_FEED_ADDRESS = _params.ethUsdChainlinkFeedAddress;
ETH_USD_CHAINLINK_FEED_DECIMALS = AggregatorV3Interface(ETH_USD_CHAINLINK_FEED_ADDRESS).decimals();
ETH_USD_CHAINLINK_FEED_PRECISION = 10 ** uint256(ETH_USD_CHAINLINK_FEED_DECIMALS);
maximumEthUsdOracleDelay = _params.maxEthUsdOracleDelay;
}
/// @notice The ```_setMaximumEthUsdOracleDelay``` function sets the max oracle delay to determine if Chainlink data is stale
/// @param _newMaxOracleDelay The new max oracle delay
function _setMaximumEthUsdOracleDelay(uint256 _newMaxOracleDelay) internal {
emit SetMaximumEthUsdOracleDelay({
oldMaxOracleDelay: maximumEthUsdOracleDelay,
newMaxOracleDelay: _newMaxOracleDelay
});
maximumEthUsdOracleDelay = _newMaxOracleDelay;
}
function setMaximumEthUsdOracleDelay(uint256 _newMaxOracleDelay) external virtual;
/// @notice The ```_getEthUsdChainlinkPrice``` function is called to get the eth/usd price from Chainlink
/// @dev If data is stale or negative, set bad data to true and return
/// @return _isBadData If the data is stale
/// @return _updatedAt The timestamp of the last update
/// @return _usdPerEth The eth/usd price
function _getEthUsdChainlinkPrice()
internal
view
returns (bool _isBadData, uint256 _updatedAt, uint256 _usdPerEth)
{
(, int256 _answer, , uint256 _ethUsdChainlinkUpdatedAt, ) = AggregatorV3Interface(
ETH_USD_CHAINLINK_FEED_ADDRESS
).latestRoundData();
// If data is stale or negative, set bad data to true and return
_isBadData = _answer <= 0 || ((block.timestamp - _ethUsdChainlinkUpdatedAt) > maximumEthUsdOracleDelay);
_updatedAt = _ethUsdChainlinkUpdatedAt;
_usdPerEth = uint256(_answer);
}
/// @notice The ```getEthUsdChainlinkPrice``` function is called to get the eth/usd price from Chainlink
/// @return _isBadData If the data is stale
/// @return _updatedAt The timestamp of the last update
/// @return _usdPerEth The eth/usd price
function getEthUsdChainlinkPrice()
external
view
virtual
returns (bool _isBadData, uint256 _updatedAt, uint256 _usdPerEth)
{
(_isBadData, _updatedAt, _usdPerEth) = _getEthUsdChainlinkPrice();
}
}
src/abstracts/FraxUsdChainlinkOracleWithMaxDelay.sol
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ================ FraxUsdChainlinkOracleWithMaxDelay =================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Author
// Drake Evans: https://github.com/DrakeEvans
// Reviewers
// Dennis: https://github.com/denett
// ====================================================================
import { AggregatorV3Interface } from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import { ERC165Storage } from "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
import {
IFraxUsdChainlinkOracleWithMaxDelay
} from "interfaces/oracles/abstracts/IFraxUsdChainlinkOracleWithMaxDelay.sol";
struct ConstructorParams {
address fraxUsdChainlinkFeedAddress;
uint256 fraxUsdMaximumOracleDelay;
}
/// @title FraxUsdChainlinkOracleWithMaxDelay
/// @author Drake Evans (Frax Finance) https://github.com/drakeevans
/// @notice An abstract oracle for getting frax/usd prices from Chainlink
abstract contract FraxUsdChainlinkOracleWithMaxDelay is ERC165Storage, IFraxUsdChainlinkOracleWithMaxDelay {
/// @notice Chainlink aggregator
address public immutable FRAX_USD_CHAINLINK_FEED_ADDRESS;
/// @notice Decimals of FRAX/USD chainlink feed
uint8 public immutable FRAX_USD_CHAINLINK_FEED_DECIMALS;
/// @notice Precision of FRAX/USD chainlink feed
uint256 public immutable FRAX_USD_CHAINLINK_FEED_PRECISION;
/// @notice Maximum delay of Chainlink data, after which it is considered stale
uint256 public maximumFraxUsdOracleDelay;
constructor(ConstructorParams memory _params) {
_registerInterface({ interfaceId: type(IFraxUsdChainlinkOracleWithMaxDelay).interfaceId });
FRAX_USD_CHAINLINK_FEED_ADDRESS = _params.fraxUsdChainlinkFeedAddress;
FRAX_USD_CHAINLINK_FEED_DECIMALS = AggregatorV3Interface(FRAX_USD_CHAINLINK_FEED_ADDRESS).decimals();
FRAX_USD_CHAINLINK_FEED_PRECISION = 10 ** uint256(FRAX_USD_CHAINLINK_FEED_DECIMALS);
maximumFraxUsdOracleDelay = _params.fraxUsdMaximumOracleDelay;
}
/// @notice The ```_setMaximumFraxUsdOracleDelay``` function sets the max oracle delay to determine if Chainlink data is stale
/// @param _newMaxOracleDelay The new max oracle delay
function _setMaximumFraxUsdOracleDelay(uint256 _newMaxOracleDelay) internal {
emit SetMaximumFraxUsdOracleDelay({
oldMaxOracleDelay: maximumFraxUsdOracleDelay,
newMaxOracleDelay: _newMaxOracleDelay
});
maximumFraxUsdOracleDelay = _newMaxOracleDelay;
}
function setMaximumFraxUsdOracleDelay(uint256 _newMaxOracleDelay) external virtual;
/// @notice The ```_getFraxUsdChainlinkPrice``` function is called to get the frax/usd price from Chainlink
/// @dev If data is stale or negative, set bad data to true and return
/// @return _isBadData If the data is stale
/// @return _updatedAt The timestamp of the last update
/// @return _usdPerFrax The frax/usd price
function _getFraxUsdChainlinkPrice()
internal
view
returns (bool _isBadData, uint256 _updatedAt, uint256 _usdPerFrax)
{
(, int256 _answer, , uint256 _fraxUsdChainlinkUpdatedAt, ) = AggregatorV3Interface(
FRAX_USD_CHAINLINK_FEED_ADDRESS
).latestRoundData();
// If data is stale or negative, set bad data to true and return
_isBadData = _answer <= 0 || ((block.timestamp - _fraxUsdChainlinkUpdatedAt) > maximumFraxUsdOracleDelay);
_updatedAt = _fraxUsdChainlinkUpdatedAt;
_usdPerFrax = uint256(_answer);
}
/// @notice The ```getFraxUsdChainlinkPrice``` function is called to get the frax/usd price from Chainlink
/// @return _isBadData If the data is stale
/// @return _updatedAt The timestamp of the last update
/// @return _usdPerFrax The frax/usd price
function getFraxUsdChainlinkPrice()
external
view
virtual
returns (bool _isBadData, uint256 _updatedAt, uint256 _usdPerFrax)
{
(_isBadData, _updatedAt, _usdPerFrax) = _getFraxUsdChainlinkPrice();
}
}
src/abstracts/FraxUsdcUniswapV3SingleTwapOracle.sol
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ================ FraxUsdcUniswapV3SingleTwapOracle =================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Author
// Drake Evans: https://github.com/DrakeEvans
// Reviewers
// Dennis: https://github.com/denett
// ====================================================================
import { IStaticOracle } from "@mean-finance/uniswap-v3-oracle/solidity/interfaces/IStaticOracle.sol";
import { ERC165Storage } from "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
import {
IFraxUsdcUniswapV3SingleTwapOracle
} from "interfaces/oracles/abstracts/IFraxUsdcUniswapV3SingleTwapOracle.sol";
struct ConstructorParams {
address fraxUsdcUniswapV3PairAddress;
uint32 fraxUsdcTwapDuration;
address fraxUsdcTwapBaseToken;
address fraxUsdcTwapQuoteToken;
}
/// @title UniswapV3SingleTwapOracle
/// @author Drake Evans (Frax Finance) https://github.com/drakeevans
/// @notice An oracle for UniV3 Twap prices
abstract contract FraxUsdcUniswapV3SingleTwapOracle is ERC165Storage, IFraxUsdcUniswapV3SingleTwapOracle {
/// @notice address of the Uniswap V3 pair
address public immutable FRAX_USDC_UNI_V3_PAIR_ADDRESS;
/// @notice The precision of the twap
uint128 public constant FRAX_USDC_TWAP_PRECISION = 1e18;
/// @notice The base token of the twap
address public immutable FRAX_USDC_UNISWAP_V3_TWAP_BASE_TOKEN;
/// @notice The quote token of the twap
address public immutable FRAX_USDC_UNISWAP_V3_TWAP_QUOTE_TOKEN;
/// @notice The duration of the twap
uint32 public fraxUsdcTwapDuration;
constructor(ConstructorParams memory _params) {
_registerInterface({ interfaceId: type(IFraxUsdcUniswapV3SingleTwapOracle).interfaceId });
FRAX_USDC_UNI_V3_PAIR_ADDRESS = _params.fraxUsdcUniswapV3PairAddress;
fraxUsdcTwapDuration = _params.fraxUsdcTwapDuration;
FRAX_USDC_UNISWAP_V3_TWAP_BASE_TOKEN = _params.fraxUsdcTwapBaseToken;
FRAX_USDC_UNISWAP_V3_TWAP_QUOTE_TOKEN = _params.fraxUsdcTwapQuoteToken;
}
/// @notice The ```_setFraxUsdcTwapDuration``` function sets duration of the twap
/// @param _newTwapDuration The new twap duration
function _setFraxUsdcTwapDuration(uint32 _newTwapDuration) internal {
emit SetFraxUsdcTwapDuration({ oldTwapDuration: fraxUsdcTwapDuration, newTwapDuration: _newTwapDuration });
fraxUsdcTwapDuration = _newTwapDuration;
}
function setFraxUsdcTwapDuration(uint32 _newTwapDuration) external virtual;
/// @notice The ```_getFraxUsdcUniswapV3Twap``` function is called to get the twap
/// @return _twap The twap price
function _getFraxUsdcUniswapV3Twap() internal view returns (uint256 _twap) {
address[] memory _pools = new address[](1);
_pools[0] = FRAX_USDC_UNI_V3_PAIR_ADDRESS;
_twap = IStaticOracle(0xB210CE856631EeEB767eFa666EC7C1C57738d438).quoteSpecificPoolsWithTimePeriod({
baseAmount: FRAX_USDC_TWAP_PRECISION,
baseToken: FRAX_USDC_UNISWAP_V3_TWAP_BASE_TOKEN,
quoteToken: FRAX_USDC_UNISWAP_V3_TWAP_QUOTE_TOKEN,
pools: _pools,
period: fraxUsdcTwapDuration
});
}
/// @notice The ```getFraxUsdcUniswapV3Twap``` function is called to get the twap
/// @return _twap The twap price
function getFraxUsdcUniswapV3Twap() external view virtual returns (uint256 _twap) {
_twap = _getFraxUsdcUniswapV3Twap();
}
}
src/abstracts/UniswapV3SingleTwapOracle.sol
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ==================== UniswapV3SingleTwapOracle =====================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Author
// Drake Evans: https://github.com/DrakeEvans
// Reviewers
// Dennis: https://github.com/denett
// ====================================================================
import { IStaticOracle } from "@mean-finance/uniswap-v3-oracle/solidity/interfaces/IStaticOracle.sol";
import { ERC165Storage } from "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
import { IUniswapV3SingleTwapOracle } from "interfaces/oracles/abstracts/IUniswapV3SingleTwapOracle.sol";
struct ConstructorParams {
address uniswapV3PairAddress;
uint32 twapDuration;
address baseToken;
address quoteToken;
}
/// @title UniswapV3SingleTwapOracle
/// @author Drake Evans (Frax Finance) https://github.com/drakeevans
/// @notice An oracle for UniV3 Twap prices
abstract contract UniswapV3SingleTwapOracle is ERC165Storage, IUniswapV3SingleTwapOracle {
/// @notice address of the Uniswap V3 pair
address public immutable UNI_V3_PAIR_ADDRESS;
/// @notice The precision of the twap
uint128 public constant TWAP_PRECISION = 1e18;
/// @notice The base token of the twap
address public immutable UNISWAP_V3_TWAP_BASE_TOKEN;
/// @notice The quote token of the twap
address public immutable UNISWAP_V3_TWAP_QUOTE_TOKEN;
/// @notice The duration of the twap
uint32 public twapDuration;
constructor(ConstructorParams memory _params) {
_registerInterface({ interfaceId: type(IUniswapV3SingleTwapOracle).interfaceId });
UNI_V3_PAIR_ADDRESS = _params.uniswapV3PairAddress;
twapDuration = _params.twapDuration;
UNISWAP_V3_TWAP_BASE_TOKEN = _params.baseToken;
UNISWAP_V3_TWAP_QUOTE_TOKEN = _params.quoteToken;
}
/// @notice The ```_setTwapDuration``` function sets duration of the twap
/// @param _newTwapDuration The new twap duration
function _setTwapDuration(uint32 _newTwapDuration) internal {
emit SetTwapDuration({ oldTwapDuration: twapDuration, newTwapDuration: _newTwapDuration });
twapDuration = _newTwapDuration;
}
function setTwapDuration(uint32 _newTwapDuration) external virtual;
/// @notice The ```_getUniswapV3Twap``` function is called to get the twap
/// @return _twap The twap price
function _getUniswapV3Twap() internal view returns (uint256 _twap) {
address[] memory _pools = new address[](1);
_pools[0] = UNI_V3_PAIR_ADDRESS;
_twap = IStaticOracle(0xB210CE856631EeEB767eFa666EC7C1C57738d438).quoteSpecificPoolsWithTimePeriod({
baseAmount: TWAP_PRECISION,
baseToken: UNISWAP_V3_TWAP_BASE_TOKEN,
quoteToken: UNISWAP_V3_TWAP_QUOTE_TOKEN,
pools: _pools,
period: twapDuration
});
}
/// @notice The ```getUniswapV3Twap``` function is called to get the twap
/// @return _twap The twap price
function getUniswapV3Twap() external view virtual returns (uint256 _twap) {
_twap = _getUniswapV3Twap();
}
}
src/interfaces/IDualOracle.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface IDualOracle is IERC165 {
function ORACLE_PRECISION() external view returns (uint256);
function BASE_TOKEN_0() external view returns (address);
function BASE_TOKEN_0_DECIMALS() external view returns (uint256);
function BASE_TOKEN_1() external view returns (address);
function BASE_TOKEN_1_DECIMALS() external view returns (uint256);
function decimals() external view returns (uint8);
function getPricesNormalized() external view returns (bool _isBadData, uint256 _priceLow, uint256 _priceHigh);
function getPrices() external view returns (bool _isBadData, uint256 _priceLow, uint256 _priceHigh);
function name() external view returns (string memory);
function NORMALIZATION_0() external view returns (int256);
function NORMALIZATION_1() external view returns (int256);
function QUOTE_TOKEN_0() external view returns (address);
function QUOTE_TOKEN_0_DECIMALS() external view returns (uint256);
function QUOTE_TOKEN_1() external view returns (address);
function QUOTE_TOKEN_1_DECIMALS() external view returns (uint256);
}
src/interfaces/IVirtualPriceStableSwap.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.19;
interface IVirtualPriceStableSwap {
function get_virtual_price() external view returns (uint256);
}
src/interfaces/oracles/abstracts/IChainlinkOracleWithMaxDelay.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface IChainlinkOracleWithMaxDelay is IERC165 {
event SetMaximumOracleDelay(address oracle, uint256 oldMaxOracleDelay, uint256 newMaxOracleDelay);
function CHAINLINK_FEED_ADDRESS() external view returns (address);
function CHAINLINK_FEED_DECIMALS() external view returns (uint8);
function CHAINLINK_FEED_PRECISION() external view returns (uint256);
function getChainlinkPrice() external view returns (bool _isBadData, uint256 _updatedAt, uint256 _usdPerEth);
function maximumOracleDelay() external view returns (uint256);
function setMaximumOracleDelay(uint256 _newMaxOracleDelay) external;
}
src/interfaces/oracles/abstracts/ICurvePoolVirtualPriceOracleWithMinMax.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface ICurvePoolVirtualPriceOracleWithMinMax is IERC165 {
event SetMaximumCurvePoolVirtualPrice(uint256 oldMaximum, uint256 newMaximum);
event SetMinimumCurvePoolVirtualPrice(uint256 oldMinimum, uint256 newMinimum);
function CURVE_POOL_VIRTUAL_PRICE_ADDRESS() external view returns (address);
function CURVE_POOL_VIRTUAL_PRICE_PRECISION() external view returns (uint256);
function getCurvePoolVirtualPrice() external view returns (uint256 _virtualPrice);
function maximumCurvePoolVirtualPrice() external view returns (uint256);
function minimumCurvePoolVirtualPrice() external view returns (uint256);
function setMaximumCurvePoolVirtualPrice(uint256 _newMaximum) external;
function setMinimumCurvePoolVirtualPrice(uint256 _newMinimum) external;
}
src/interfaces/oracles/abstracts/IEthUsdChainlinkOracleWithMaxDelay.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface IEthUsdChainlinkOracleWithMaxDelay is IERC165 {
event SetMaximumEthUsdOracleDelay(uint256 oldMaxOracleDelay, uint256 newMaxOracleDelay);
function ETH_USD_CHAINLINK_FEED_ADDRESS() external view returns (address);
function ETH_USD_CHAINLINK_FEED_DECIMALS() external view returns (uint8);
function ETH_USD_CHAINLINK_FEED_PRECISION() external view returns (uint256);
function maximumEthUsdOracleDelay() external view returns (uint256);
function getEthUsdChainlinkPrice() external view returns (bool _isBadData, uint256 _updatedAt, uint256 _usdPerEth);
function setMaximumEthUsdOracleDelay(uint256 _newMaxOracleDelay) external;
}
src/interfaces/oracles/abstracts/IFraxUsdChainlinkOracleWithMaxDelay.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface IFraxUsdChainlinkOracleWithMaxDelay is IERC165 {
event SetMaximumFraxUsdOracleDelay(uint256 oldMaxOracleDelay, uint256 newMaxOracleDelay);
function FRAX_USD_CHAINLINK_FEED_ADDRESS() external view returns (address);
function FRAX_USD_CHAINLINK_FEED_DECIMALS() external view returns (uint8);
function FRAX_USD_CHAINLINK_FEED_PRECISION() external view returns (uint256);
function maximumFraxUsdOracleDelay() external view returns (uint256);
function getFraxUsdChainlinkPrice()
external
view
returns (bool _isBadData, uint256 _updatedAt, uint256 _usdPerFrax);
function setMaximumFraxUsdOracleDelay(uint256 _newMaxOracleDelay) external;
}
src/interfaces/oracles/abstracts/IFraxUsdcUniswapV3SingleTwapOracle.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface IFraxUsdcUniswapV3SingleTwapOracle is IERC165 {
event SetFraxUsdcTwapDuration(uint256 oldTwapDuration, uint256 newTwapDuration);
function FRAX_USDC_TWAP_PRECISION() external view returns (uint128);
function FRAX_USDC_UNISWAP_V3_TWAP_BASE_TOKEN() external view returns (address);
function FRAX_USDC_UNISWAP_V3_TWAP_QUOTE_TOKEN() external view returns (address);
function FRAX_USDC_UNI_V3_PAIR_ADDRESS() external view returns (address);
function getFraxUsdcUniswapV3Twap() external view returns (uint256 _twap);
function fraxUsdcTwapDuration() external view returns (uint32);
function setFraxUsdcTwapDuration(uint32 _newTwapDuration) external;
}
src/interfaces/oracles/abstracts/IUniswapV3SingleTwapOracle.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface IUniswapV3SingleTwapOracle is IERC165 {
event SetTwapDuration(uint256 oldTwapDuration, uint256 newTwapDuration);
function TWAP_PRECISION() external view returns (uint128);
function UNISWAP_V3_TWAP_BASE_TOKEN() external view returns (address);
function UNISWAP_V3_TWAP_QUOTE_TOKEN() external view returns (address);
function UNI_V3_PAIR_ADDRESS() external view returns (address);
function getUniswapV3Twap() external view returns (uint256 _twap);
function twapDuration() external view returns (uint32);
function setTwapDuration(uint32 _newTwapDuration) external;
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "none"
},
"libraries": {},
"optimizer": {
"runs": 1000000,
"enabled": true
},
"evmVersion": "london",
"remappings": [
":@chainlink/=node_modules/@chainlink/",
":@eth-optimism/=node_modules/@eth-optimism/",
":@mean-finance/=node_modules/@mean-finance/",
":@openzeppelin/=node_modules/@openzeppelin/",
":@rari-capital/=node_modules/@rari-capital/",
":@uniswap/=node_modules/@uniswap/",
":base64-sol/=node_modules/base64-sol/",
":deploy/=deploy/",
":ds-test/=lib/frax-standard-solidity/lib/forge-std/lib/ds-test/src/",
":forge-std/=lib/frax-standard-solidity/lib/forge-std/src/",
":frax-standard-solidity/=lib/frax-standard-solidity/src/",
":frax-std/=lib/frax-standard-solidity/src/",
":hardhat/=node_modules/hardhat/",
":interfaces/=src/interfaces/",
":script/=script/",
":solhint/=node_modules/solhint/",
":solidity-bytes-utils/=node_modules/solidity-bytes-utils/",
":src/=src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.