Skip to content

Commit 1ed0ca4

Browse files
authored
Merge pull request #51 from morpho-org/feat/interfaces
feat(ifc): add interfaces
2 parents ac9b8ba + 467d380 commit 1ed0ca4

File tree

5 files changed

+53
-15
lines changed

5 files changed

+53
-15
lines changed

src/ChainlinkOracle.sol

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22
pragma solidity 0.8.21;
33

4+
import {IChainlinkOracle} from "./interfaces/IChainlinkOracle.sol";
45
import {IOracle} from "../lib/morpho-blue/src/interfaces/IOracle.sol";
56

67
import {AggregatorV3Interface, ChainlinkDataFeedLib} from "./libraries/ChainlinkDataFeedLib.sol";
@@ -12,27 +13,32 @@ import {Math} from "../lib/openzeppelin-contracts/contracts/utils/math/Math.sol"
1213
/// @author Morpho Labs
1314
/// @custom:contact [email protected]
1415
/// @notice Morpho Blue oracle using Chainlink-compliant feeds.
15-
contract ChainlinkOracle is IOracle {
16+
contract ChainlinkOracle is IChainlinkOracle {
1617
using Math for uint256;
1718
using VaultLib for IERC4626;
1819
using ChainlinkDataFeedLib for AggregatorV3Interface;
1920

2021
/* IMMUTABLES */
2122

22-
/// @notice Vault.
23+
/// @inheritdoc IChainlinkOracle
2324
IERC4626 public immutable VAULT;
24-
/// @notice Vault conversion sample. The sample amount of shares used to convert to the underlying asset.
25-
/// @notice Should be chosen such that converting `VAULT_CONVERSION_SAMPLE` to assets has enough precision.
25+
26+
/// @inheritdoc IChainlinkOracle
2627
uint256 public immutable VAULT_CONVERSION_SAMPLE;
27-
/// @notice First base feed.
28+
29+
/// @inheritdoc IChainlinkOracle
2830
AggregatorV3Interface public immutable BASE_FEED_1;
29-
/// @notice Second base feed.
31+
32+
/// @inheritdoc IChainlinkOracle
3033
AggregatorV3Interface public immutable BASE_FEED_2;
31-
/// @notice First quote feed.
34+
35+
/// @inheritdoc IChainlinkOracle
3236
AggregatorV3Interface public immutable QUOTE_FEED_1;
33-
/// @notice Second quote feed.
37+
38+
/// @inheritdoc IChainlinkOracle
3439
AggregatorV3Interface public immutable QUOTE_FEED_2;
35-
/// @notice Price scale factor, computed at contract creation.
40+
41+
/// @inheritdoc IChainlinkOracle
3642
uint256 public immutable SCALE_FACTOR;
3743

3844
/* CONSTRUCTOR */
@@ -50,7 +56,9 @@ contract ChainlinkOracle is IOracle {
5056
/// @param baseFeed2 Second base feed. Pass address zero if the price = 1.
5157
/// @param quoteFeed1 First quote feed. Pass address zero if the price = 1.
5258
/// @param quoteFeed2 Second quote feed. Pass address zero if the price = 1.
53-
/// @param vaultConversionSample Vault conversion sample. Pass 1 if the oracle does not use a vault.
59+
/// @param vaultConversionSample The sample amount of vault shares used to convert to the underlying asset.
60+
/// Pass 1 if the oracle does not use a vault. Should be chosen such that converting `vaultConversionSample` to
61+
/// assets has enough precision.
5462
/// @param baseTokenDecimals Base token decimals.
5563
/// @param quoteTokenDecimals Quote token decimals.
5664
constructor(

src/interfaces/AggregatorV3Interface.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
pragma solidity ^0.8.0;
2+
pragma solidity >=0.5.0;
33

44
/// @dev From
55
/// https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol.

src/interfaces/IChainlinkOracle.sol

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity >=0.5.0;
3+
4+
import {IERC4626} from "./IERC4626.sol";
5+
import {AggregatorV3Interface} from "./AggregatorV3Interface.sol";
6+
import {IOracle} from "../../lib/morpho-blue/src/interfaces/IOracle.sol";
7+
8+
interface IChainlinkOracle is IOracle {
9+
/// @notice Returns the address of the ERC4626 vault.
10+
function VAULT() external view returns (IERC4626);
11+
12+
/// @notice Returns the vault conversion sample.
13+
function VAULT_CONVERSION_SAMPLE() external view returns (uint256);
14+
15+
/// @notice Returns the address of the first Chainlink base feed.
16+
function BASE_FEED_1() external view returns (AggregatorV3Interface);
17+
18+
/// @notice Returns the address of the second Chainlink base feed.
19+
function BASE_FEED_2() external view returns (AggregatorV3Interface);
20+
21+
/// @notice Returns the address of the first Chainlink quote feed.
22+
function QUOTE_FEED_1() external view returns (AggregatorV3Interface);
23+
24+
/// @notice Returns the address of the second Chainlink quote feed.
25+
function QUOTE_FEED_2() external view returns (AggregatorV3Interface);
26+
27+
/// @notice Returns the price scale factor, calculated at contract creation.
28+
function SCALE_FACTOR() external view returns (uint256);
29+
}

src/interfaces/IERC4626.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
2-
pragma solidity ^0.8.0;
2+
pragma solidity >=0.5.0;
33

44
interface IERC4626 {
55
function convertToAssets(uint256) external view returns (uint256);

test/ChainlinkOracleTest.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ contract ChainlinkOracleTest is Test {
5757
}
5858

5959
function testOracleWbtcEth() public {
60-
ChainlinkOracle oracle = new ChainlinkOracle(vaultZero,wBtcBtcFeed, btcEthFeed, feedZero, feedZero, 1, 8, 18);
60+
ChainlinkOracle oracle = new ChainlinkOracle(vaultZero, wBtcBtcFeed, btcEthFeed, feedZero, feedZero, 1, 8, 18);
6161
(, int256 firstBaseAnswer,,,) = wBtcBtcFeed.latestRoundData();
6262
(, int256 secondBaseAnswer,,,) = btcEthFeed.latestRoundData();
6363
assertEq(oracle.price(), (uint256(firstBaseAnswer) * uint256(secondBaseAnswer) * 10 ** (36 + 18 - 8 - 8 - 18)));
@@ -98,8 +98,9 @@ contract ChainlinkOracleTest is Test {
9898
function testNegativeAnswer(int256 price) public {
9999
price = bound(price, type(int256).min, -1);
100100
ChainlinkAggregatorMock aggregator = new ChainlinkAggregatorMock();
101-
ChainlinkOracle oracle =
102-
new ChainlinkOracle(vaultZero, AggregatorV3Interface(address(aggregator)), feedZero, feedZero, feedZero, 1, 18, 0);
101+
ChainlinkOracle oracle = new ChainlinkOracle(
102+
vaultZero, AggregatorV3Interface(address(aggregator)), feedZero, feedZero, feedZero, 1, 18, 0
103+
);
103104
aggregator.setAnwser(price);
104105
vm.expectRevert(bytes(ErrorsLib.NEGATIVE_ANSWER));
105106
oracle.price();

0 commit comments

Comments
 (0)