Skip to content

Commit cfb7616

Browse files
authored
Merge pull request #88 from perpetual-protocol/release/v0.6.7
Release/v0.6.7
2 parents 92b2ccf + 9551a9a commit cfb7616

File tree

7 files changed

+39
-25
lines changed

7 files changed

+39
-25
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
## [0.6.7] - 2023-05-05
11+
- Add `IPriceFeedDispatcher.decimals` back for backward compatible.
12+
13+
## [0.6.6] - 2023-05-05
14+
- Add `PriceFeedDispatcher.getPrice` for backward compatible.
15+
1016
## [0.6.5] - 2023-03-31
1117
- Refine natspec
1218

contracts/ChainlinkPriceFeedV3.sol

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import { Address } from "@openzeppelin/contracts/utils/Address.sol";
55
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
66
import { AggregatorV3Interface } from "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
77
import { IChainlinkPriceFeed } from "./interface/IChainlinkPriceFeed.sol";
8+
import { IPriceFeed } from "./interface/IPriceFeed.sol";
89
import { IChainlinkPriceFeedV3 } from "./interface/IChainlinkPriceFeedV3.sol";
910
import { IPriceFeedUpdate } from "./interface/IPriceFeedUpdate.sol";
1011
import { BlockContext } from "./base/BlockContext.sol";
1112
import { CachedTwap } from "./twap/CachedTwap.sol";
1213

13-
contract ChainlinkPriceFeedV3 is IChainlinkPriceFeedV3, IPriceFeedUpdate, BlockContext, CachedTwap {
14+
contract ChainlinkPriceFeedV3 is IPriceFeed, IChainlinkPriceFeedV3, IPriceFeedUpdate, BlockContext, CachedTwap {
1415
using SafeMath for uint256;
1516
using Address for address;
1617

@@ -75,7 +76,10 @@ contract ChainlinkPriceFeedV3 is IChainlinkPriceFeedV3, IPriceFeedUpdate, BlockC
7576
return _lastValidTimestamp;
7677
}
7778

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

@@ -115,7 +119,7 @@ contract ChainlinkPriceFeedV3 is IChainlinkPriceFeedV3, IPriceFeedUpdate, BlockC
115119
return _timeout;
116120
}
117121

118-
/// @inheritdoc IChainlinkPriceFeedV3
122+
/// @inheritdoc IPriceFeed
119123
function decimals() external view override returns (uint8) {
120124
return _decimals;
121125
}

contracts/PriceFeedDispatcher.sol

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
66
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
77
import { AggregatorV3Interface } from "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
88
import { BlockContext } from "./base/BlockContext.sol";
9+
import { IPriceFeed } from "./interface/IPriceFeed.sol";
910
import { IPriceFeedDispatcher } from "./interface/IPriceFeedDispatcher.sol";
1011
import { UniswapV3PriceFeed } from "./UniswapV3PriceFeed.sol";
1112
import { ChainlinkPriceFeedV3 } from "./ChainlinkPriceFeedV3.sol";
1213

13-
contract PriceFeedDispatcher is IPriceFeedDispatcher, Ownable, BlockContext {
14+
contract PriceFeedDispatcher is IPriceFeed, IPriceFeedDispatcher, Ownable, BlockContext {
1415
using SafeMath for uint256;
1516
using Address for address;
1617

@@ -57,31 +58,43 @@ contract PriceFeedDispatcher is IPriceFeedDispatcher, Ownable, BlockContext {
5758
// EXTERNAL VIEW
5859
//
5960

60-
/// @inheritdoc IPriceFeedDispatcher
61-
function getDispatchedPrice(uint256 interval) external view override returns (uint256) {
62-
if (isToUseUniswapV3PriceFeed()) {
63-
return _formatFromDecimalsToX10_18(_uniswapV3PriceFeed.getPrice(), _uniswapV3PriceFeed.decimals());
64-
}
65-
66-
return _formatFromDecimalsToX10_18(_chainlinkPriceFeedV3.getPrice(interval), _chainlinkPriceFeedV3.decimals());
61+
/// @inheritdoc IPriceFeed
62+
function getPrice(uint256 interval) external view override returns (uint256) {
63+
return getDispatchedPrice(interval);
6764
}
6865

66+
/// @inheritdoc IPriceFeedDispatcher
6967
function getChainlinkPriceFeedV3() external view override returns (address) {
7068
return address(_chainlinkPriceFeedV3);
7169
}
7270

71+
/// @inheritdoc IPriceFeedDispatcher
7372
function getUniswapV3PriceFeed() external view override returns (address) {
7473
return address(_uniswapV3PriceFeed);
7574
}
7675

77-
function decimals() external pure override returns (uint8) {
76+
//
77+
// EXTERNAL PURE
78+
//
79+
80+
/// @inheritdoc IPriceFeed
81+
function decimals() external pure override(IPriceFeed, IPriceFeedDispatcher) returns (uint8) {
7882
return _DECIMALS;
7983
}
8084

8185
//
8286
// PUBLIC
8387
//
8488

89+
/// @inheritdoc IPriceFeedDispatcher
90+
function getDispatchedPrice(uint256 interval) public view override returns (uint256) {
91+
if (isToUseUniswapV3PriceFeed()) {
92+
return _formatFromDecimalsToX10_18(_uniswapV3PriceFeed.getPrice(), _uniswapV3PriceFeed.decimals());
93+
}
94+
95+
return _formatFromDecimalsToX10_18(_chainlinkPriceFeedV3.getPrice(interval), _chainlinkPriceFeedV3.decimals());
96+
}
97+
8598
function isToUseUniswapV3PriceFeed() public view returns (bool) {
8699
return
87100
address(_uniswapV3PriceFeed) != address(0) &&

contracts/interface/IChainlinkPriceFeedV3.sol

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ interface IChainlinkPriceFeedV3 is IChainlinkPriceFeedV3Event {
3535
/// @return timestamp The last cached valid timestamp
3636
function getLastValidTimestamp() external view returns (uint256 timestamp);
3737

38-
/// @notice If the interval is zero, returns the latest valid price.
39-
/// Else, returns TWAP calculating with the latest valid price and timestamp.
40-
/// @dev This is the view version of cacheTwap()
41-
/// @param interval TWAP interval
42-
/// @return price The last valid price or TWAP
43-
function getPrice(uint256 interval) external view returns (uint256 price);
44-
4538
/// @notice Retrieve the latest price and timestamp from Chainlink aggregator,
4639
/// or return the last cached valid price and timestamp if the aggregator hasn't been updated or is frozen.
4740
/// @return price The latest valid price
@@ -58,7 +51,4 @@ interface IChainlinkPriceFeedV3 is IChainlinkPriceFeedV3Event {
5851

5952
/// @return period The timeout period
6053
function getTimeout() external view returns (uint256 period);
61-
62-
/// @return decimals The decimals of price feed
63-
function decimals() external view returns (uint8 decimals);
6454
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@perp/perp-oracle-contract",
3-
"version": "0.6.5",
3+
"version": "0.6.7",
44
"description": "Perpetual Protocol Curie (v2) oracle contracts - v0.5.0 is not an audited version",
55
"license": "GPL-3.0-or-later",
66
"author": {

test/foundry/PriceFeedDispatcher.t.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ contract PriceFeedDispatcherTest is IPriceFeedDispatcherEvent, PriceFeedDispatch
179179
function _dispatchPrice_and_assertEq_getDispatchedPrice(uint256 price) internal {
180180
_priceFeedDispatcher.dispatchPrice(0);
181181
assertEq(_priceFeedDispatcher.getDispatchedPrice(0), price);
182+
assertEq(_priceFeedDispatcher.getPrice(0), price);
182183
}
183184

184185
function _expect_emit_event_from_PriceFeedDispatcher() internal {

0 commit comments

Comments
 (0)