Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refact: interfaces of PriceFeedDispatcher and ChainlinkPriceFeedV3 #85

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions contracts/ChainlinkPriceFeedV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
import { AggregatorV3Interface } from "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import { IChainlinkPriceFeed } from "./interface/IChainlinkPriceFeed.sol";
import { IPriceFeed } from "./interface/IPriceFeed.sol";
import { IChainlinkPriceFeedV3 } from "./interface/IChainlinkPriceFeedV3.sol";
import { IPriceFeedUpdate } from "./interface/IPriceFeedUpdate.sol";
import { BlockContext } from "./base/BlockContext.sol";
import { CachedTwap } from "./twap/CachedTwap.sol";

contract ChainlinkPriceFeedV3 is IChainlinkPriceFeedV3, IPriceFeedUpdate, BlockContext, CachedTwap {
contract ChainlinkPriceFeedV3 is IPriceFeed, IChainlinkPriceFeedV3, IPriceFeedUpdate, BlockContext, CachedTwap {
using SafeMath for uint256;
using Address for address;

Expand Down Expand Up @@ -75,7 +76,10 @@ contract ChainlinkPriceFeedV3 is IChainlinkPriceFeedV3, IPriceFeedUpdate, BlockC
return _lastValidTimestamp;
}

/// @inheritdoc IChainlinkPriceFeedV3
/// @inheritdoc IPriceFeed
/// @dev This is the view version of cacheTwap().
/// If the interval is zero, returns the latest valid price.
/// Else, returns TWAP calculating with the latest valid price and timestamp.
function getPrice(uint256 interval) external view override returns (uint256) {
(uint256 latestValidPrice, uint256 latestValidTime) = _getLatestOrCachedPrice();

Expand Down Expand Up @@ -115,7 +119,7 @@ contract ChainlinkPriceFeedV3 is IChainlinkPriceFeedV3, IPriceFeedUpdate, BlockC
return _timeout;
}

/// @inheritdoc IChainlinkPriceFeedV3
/// @inheritdoc IPriceFeed
function decimals() external view override returns (uint8) {
return _decimals;
}
Expand Down
12 changes: 10 additions & 2 deletions contracts/PriceFeedDispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { AggregatorV3Interface } from "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import { BlockContext } from "./base/BlockContext.sol";
import { IPriceFeed } from "./interface/IPriceFeed.sol";
import { IPriceFeedDispatcher } from "./interface/IPriceFeedDispatcher.sol";
import { UniswapV3PriceFeed } from "./UniswapV3PriceFeed.sol";
import { ChainlinkPriceFeedV3 } from "./ChainlinkPriceFeedV3.sol";

contract PriceFeedDispatcher is IPriceFeedDispatcher, Ownable, BlockContext {
contract PriceFeedDispatcher is IPriceFeed, IPriceFeedDispatcher, Ownable, BlockContext {
using SafeMath for uint256;
using Address for address;

Expand Down Expand Up @@ -57,19 +58,26 @@ contract PriceFeedDispatcher is IPriceFeedDispatcher, Ownable, BlockContext {
// EXTERNAL VIEW
//

/// @inheritdoc IPriceFeedDispatcher
/// @inheritdoc IPriceFeed
function getPrice(uint256 interval) external view override returns (uint256) {
return getDispatchedPrice(interval);
}

/// @inheritdoc IPriceFeedDispatcher
function getChainlinkPriceFeedV3() external view override returns (address) {
return address(_chainlinkPriceFeedV3);
}

/// @inheritdoc IPriceFeedDispatcher
function getUniswapV3PriceFeed() external view override returns (address) {
return address(_uniswapV3PriceFeed);
}

//
// EXTERNAL PURE
//

/// @inheritdoc IPriceFeed
function decimals() external pure override returns (uint8) {
return _DECIMALS;
}
Expand Down
10 changes: 0 additions & 10 deletions contracts/interface/IChainlinkPriceFeedV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ interface IChainlinkPriceFeedV3 is IChainlinkPriceFeedV3Event {
/// @return timestamp The last cached valid timestamp
function getLastValidTimestamp() external view returns (uint256 timestamp);

/// @notice If the interval is zero, returns the latest valid price.
/// Else, returns TWAP calculating with the latest valid price and timestamp.
/// @dev This is the view version of cacheTwap()
/// @param interval TWAP interval
/// @return price The last valid price or TWAP
function getPrice(uint256 interval) external view returns (uint256 price);

/// @notice Retrieve the latest price and timestamp from Chainlink aggregator,
/// or return the last cached valid price and timestamp if the aggregator hasn't been updated or is frozen.
/// @return price The latest valid price
Expand All @@ -58,7 +51,4 @@ interface IChainlinkPriceFeedV3 is IChainlinkPriceFeedV3Event {

/// @return period The timeout period
function getTimeout() external view returns (uint256 period);

/// @return decimals The decimals of price feed
function decimals() external view returns (uint8 decimals);
}
6 changes: 0 additions & 6 deletions contracts/interface/IPriceFeedDispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,4 @@ interface IPriceFeedDispatcher is IPriceFeedDispatcherEvent {
function getChainlinkPriceFeedV3() external view returns (address);

function getUniswapV3PriceFeed() external view returns (address);

function decimals() external pure returns (uint8);

/// @dev The same as getDispatchedPrice, it's for backward-compatibility
/// @param interval The interval represents twap interval.
function getPrice(uint256 interval) external view returns (uint256);
}