Skip to content

Commit 6941f06

Browse files
Merge pull request #52 from morpho-org/post-cantina
Post cantina
2 parents ac9b8ba + 0c6815f commit 6941f06

File tree

6 files changed

+59
-17
lines changed

6 files changed

+59
-17
lines changed

lib/morpho-blue

Submodule morpho-blue updated 63 files

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: MIT
2-
pragma solidity ^0.8.0;
2+
pragma solidity >=0.5.0;
33

44
/// @dev From
5-
/// https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol.
5+
/// https://github.com/smartcontractkit/chainlink/blob/master/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol
66
interface AggregatorV3Interface {
77
function decimals() external view returns (uint8);
88

src/interfaces/IChainlinkOracle.sol

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
/// @title IChainlinkOracle
9+
/// @author Morpho Labs
10+
/// @custom:contact [email protected]
11+
/// @notice Interface of ChainlinkOracle.
12+
interface IChainlinkOracle is IOracle {
13+
/// @notice Returns the address of the ERC4626 vault.
14+
function VAULT() external view returns (IERC4626);
15+
16+
/// @notice Returns the vault conversion sample.
17+
function VAULT_CONVERSION_SAMPLE() external view returns (uint256);
18+
19+
/// @notice Returns the address of the first Chainlink base feed.
20+
function BASE_FEED_1() external view returns (AggregatorV3Interface);
21+
22+
/// @notice Returns the address of the second Chainlink base feed.
23+
function BASE_FEED_2() external view returns (AggregatorV3Interface);
24+
25+
/// @notice Returns the address of the first Chainlink quote feed.
26+
function QUOTE_FEED_1() external view returns (AggregatorV3Interface);
27+
28+
/// @notice Returns the address of the second Chainlink quote feed.
29+
function QUOTE_FEED_2() external view returns (AggregatorV3Interface);
30+
31+
/// @notice Returns the price scale factor, calculated at contract creation.
32+
function SCALE_FACTOR() external view returns (uint256);
33+
}

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)