Skip to content

Commit c05a52e

Browse files
authored
Merge pull request #13 from morpho-labs/merlin-review
Review Merlin
2 parents 7d01dae + 34949dc commit c05a52e

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

src/ChainlinkOracle.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import {IOracle} from "morpho-blue/interfaces/IOracle.sol";
55

66
import {AggregatorV3Interface, ChainlinkDataFeedLib} from "./libraries/ChainlinkDataFeedLib.sol";
77

8+
/// @title ChainlinkOracle
9+
/// @author Morpho Labs
10+
/// @custom:contact [email protected]
11+
/// @notice Morpho Blue oracle using Chainlink-compliant feeds.
812
contract ChainlinkOracle is IOracle {
913
using ChainlinkDataFeedLib for AggregatorV3Interface;
1014

11-
/* CONSTANT */
15+
/* IMMUTABLES */
1216

1317
/// @notice First base feed.
1418
AggregatorV3Interface public immutable BASE_FEED_1;
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.0;
33

4-
import {ErrorsLib} from "./ErrorsLib.sol";
54
import {AggregatorV3Interface} from "../interfaces/AggregatorV3Interface.sol";
65

6+
import {ErrorsLib} from "./ErrorsLib.sol";
7+
8+
/// @title ChainlinkDataFeedLib
9+
/// @author Morpho Labs
10+
/// @custom:contact [email protected]
11+
/// @notice Library exposing functions to interact with a Chainlink-compliant feed.
712
library ChainlinkDataFeedLib {
8-
/// @dev Performs some safety checks and returns the latest price of a feed.
13+
/// @dev Performs safety checks and returns the latest price of a `feed`.
914
/// @dev When `feed` is the address zero, returns 1.
1015
function getPrice(AggregatorV3Interface feed) internal view returns (uint256) {
1116
if (address(feed) == address(0)) return 1;
17+
1218
(, int256 answer,,,) = feed.latestRoundData();
1319
require(answer >= 0, ErrorsLib.NEGATIVE_ANSWER);
20+
1421
return uint256(answer);
1522
}
1623

17-
/// @dev Returns the number of decimals of a feed.
24+
/// @dev Returns the number of decimals of a `feed`.
1825
/// @dev When `feed` is the address zero, returns 0.
1926
function getDecimals(AggregatorV3Interface feed) internal view returns (uint256) {
2027
if (address(feed) == address(0)) return 0;
28+
2129
return feed.decimals();
2230
}
2331
}

src/libraries/ErrorsLib.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.0;
33

4+
/// @title ErrorsLib
5+
/// @author Morpho Labs
6+
/// @custom:contact [email protected]
7+
/// @notice Library exposing error messages.
48
library ErrorsLib {
9+
/// @notice Thrown when the answer returned by a Chainlink feed is negative.
510
string constant NEGATIVE_ANSWER = "negative answer";
611
}
File renamed without changes.

0 commit comments

Comments
 (0)