Skip to content

Commit 8a6bbf5

Browse files
committed
Merge branch 'feat/chainlink' of github.com:morpho-labs/morpho-blue-oracles into merlin-review
2 parents ef5cb20 + a5fdad8 commit 8a6bbf5

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

src/chainlink/Oracle4.sol renamed to src/chainlink/OracleFourFeeds.sol

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

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

8-
/// @title Oracle4
8+
/// @title OracleFourFeeds
99
/// @author Morpho Labs
1010
/// @custom:contact [email protected]
1111
/// @notice Oracle using 4 Chainlink-compliant feeds to compute the price of a collateral token quoted in a borrowable
1212
/// token within a Morpho Blue market.
13-
contract Oracle4 is IOracle {
13+
contract OracleFourFeeds is IOracle {
1414
using DataFeedLib for AggregatorV3Interface;
1515

1616
/* IMMUTABLES */

src/chainlink/Oracle2.sol renamed to src/chainlink/OracleTwoFeeds.sol

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

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

8-
/// @title Oracle2
8+
/// @title OracleTwoFeeds
99
/// @author Morpho Labs
1010
/// @custom:contact [email protected]
1111
/// @notice Oracle using 2 Chainlink-compliant feeds to compute the price of a collateral token quoted in a borrowable
1212
/// token within a Morpho Blue market.
13-
contract Oracle2 is IOracle {
13+
contract OracleTwoFeeds is IOracle {
1414
using DataFeedLib for AggregatorV3Interface;
1515

1616
/* IMMUTABLES */

test/chainlink/Oracle4Test.sol renamed to test/chainlink/OracleFourFeedsTest.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.0;
33

44
import "forge-std/Test.sol";
5-
import "src/chainlink/Oracle4.sol";
5+
import "src/chainlink/OracleFourFeeds.sol";
66
import "src/chainlink/libraries/ErrorsLib.sol";
77

88
// 8 decimals of precision
@@ -14,13 +14,13 @@ AggregatorV3Interface constant btcEthFeed = AggregatorV3Interface(0xdeb288F73706
1414
// 8 decimals of precision
1515
AggregatorV3Interface constant wBtcBtcFeed = AggregatorV3Interface(0xfdFD9C85aD200c506Cf9e21F1FD8dd01932FBB23);
1616

17-
contract OracleTest is Test {
17+
contract OracleFourFeedsTest is Test {
1818
function setUp() public {
1919
vm.selectFork(vm.createFork(vm.envString("ETH_RPC_URL")));
2020
}
2121

2222
function testOracleWbtcUsdc() public {
23-
Oracle4 oracle = new Oracle4(wBtcBtcFeed, btcUsdFeed, usdcUsdFeed, AggregatorV3Interface(address(0)), 8, 6);
23+
OracleFourFeeds oracle = new OracleFourFeeds(wBtcBtcFeed, btcUsdFeed, usdcUsdFeed, AggregatorV3Interface(address(0)), 8, 6);
2424
(, int256 firstBaseAnswer,,,) = wBtcBtcFeed.latestRoundData();
2525
(, int256 secondBaseAnswer,,,) = btcUsdFeed.latestRoundData();
2626
(, int256 quoteAnswer,,,) = usdcUsdFeed.latestRoundData();
@@ -32,7 +32,7 @@ contract OracleTest is Test {
3232
}
3333

3434
function testOracleUsdcWbtc() public {
35-
Oracle4 oracle = new Oracle4(usdcUsdFeed, AggregatorV3Interface(address(0)), wBtcBtcFeed, btcUsdFeed, 6, 8);
35+
OracleFourFeeds oracle = new OracleFourFeeds(usdcUsdFeed, AggregatorV3Interface(address(0)), wBtcBtcFeed, btcUsdFeed, 6, 8);
3636
(, int256 baseAnswer,,,) = usdcUsdFeed.latestRoundData();
3737
(, int256 firstQuoteAnswer,,,) = wBtcBtcFeed.latestRoundData();
3838
(, int256 secondQuoteAnswer,,,) = btcUsdFeed.latestRoundData();
@@ -44,8 +44,8 @@ contract OracleTest is Test {
4444
}
4545

4646
function testOracleWbtcEth() public {
47-
Oracle4 oracle =
48-
new Oracle4(wBtcBtcFeed, btcEthFeed, AggregatorV3Interface(address(0)), AggregatorV3Interface(address(0)), 8, 18);
47+
OracleFourFeeds oracle =
48+
new OracleFourFeeds(wBtcBtcFeed, btcEthFeed, AggregatorV3Interface(address(0)), AggregatorV3Interface(address(0)), 8, 18);
4949
(, int256 firstBaseAnswer,,,) = wBtcBtcFeed.latestRoundData();
5050
(, int256 secondBaseAnswer,,,) = btcEthFeed.latestRoundData();
5151
assertEq(oracle.price(), (uint256(firstBaseAnswer) * uint256(secondBaseAnswer) * 10 ** (36 + 18 - 8 - 8 - 18)));

test/chainlink/Oracle2Test.sol renamed to test/chainlink/OracleTwoFeedsTest.sol

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.0;
33

44
import "forge-std/Test.sol";
5-
import "src/chainlink/Oracle2.sol";
5+
import "src/chainlink/OracleTwoFeeds.sol";
66
import "src/chainlink/libraries/ErrorsLib.sol";
77

88
// 18 decimals of precision
@@ -30,48 +30,49 @@ contract FakeAggregator {
3030
}
3131
}
3232

33-
contract OracleTest is Test {
33+
contract OracleTwoFeedsTest is Test {
3434
function setUp() public {
3535
vm.selectFork(vm.createFork(vm.envString("ETH_RPC_URL")));
3636
}
3737

3838
function testOracleStEthUsdc() public {
39-
Oracle2 oracle = new Oracle2(stEthEthFeed, usdcEthFeed, 18, 6);
39+
OracleTwoFeeds oracle = new OracleTwoFeeds(stEthEthFeed, usdcEthFeed, 18, 6);
4040
(, int256 baseAnswer,,,) = stEthEthFeed.latestRoundData();
4141
(, int256 quoteAnswer,,,) = usdcEthFeed.latestRoundData();
4242
assertEq(oracle.price(), uint256(baseAnswer) * 10 ** (36 + 18 + 6 - 18 - 18) / uint256(quoteAnswer));
4343
}
4444

4545
function testOracleEthUsd() public {
46-
Oracle2 oracle = new Oracle2(ethUsdFeed, AggregatorV3Interface(address(0)), 18, 0);
46+
OracleTwoFeeds oracle = new OracleTwoFeeds(ethUsdFeed, AggregatorV3Interface(address(0)), 18, 0);
4747
(, int256 expectedPrice,,,) = ethUsdFeed.latestRoundData();
4848
assertEq(oracle.price(), uint256(expectedPrice) * 10 ** (36 - 18 - 8));
4949
}
5050

5151
function testOracleStEthEth() public {
52-
Oracle2 oracle = new Oracle2(stEthEthFeed, AggregatorV3Interface(address(0)), 18, 18);
52+
OracleTwoFeeds oracle = new OracleTwoFeeds(stEthEthFeed, AggregatorV3Interface(address(0)), 18, 18);
5353
(, int256 expectedPrice,,,) = stEthEthFeed.latestRoundData();
5454
assertEq(oracle.price(), uint256(expectedPrice) * 10 ** (36 + 18 - 18 - 18));
5555
assertApproxEqRel(oracle.price(), 1e36, 0.01 ether);
5656
}
5757

5858
function testOracleEthStEth() public {
59-
Oracle2 oracle = new Oracle2(AggregatorV3Interface(address(0)), stEthEthFeed, 18, 18);
59+
OracleTwoFeeds oracle = new OracleTwoFeeds(AggregatorV3Interface(address(0)), stEthEthFeed, 18, 18);
6060
(, int256 expectedPrice,,,) = stEthEthFeed.latestRoundData();
6161
assertEq(oracle.price(), 10 ** (36 + 18 + 18 - 18) / uint256(expectedPrice));
6262
assertApproxEqRel(oracle.price(), 1e36, 0.01 ether);
6363
}
6464

6565
function testOracleUsdcUsd() public {
66-
Oracle2 oracle = new Oracle2(usdcUsd, AggregatorV3Interface(address(0)), 6, 0);
66+
OracleTwoFeeds oracle = new OracleTwoFeeds(usdcUsd, AggregatorV3Interface(address(0)), 6, 0);
6767
assertApproxEqRel(oracle.price(), 1e36 / 1e6, 0.01 ether);
6868
}
6969

70-
function testNegativeAnswer() public {
70+
function testNegativeAnswer(int price) public {
71+
vm.assume(price < 0);
7172
FakeAggregator aggregator = new FakeAggregator();
72-
Oracle2 oracle =
73-
new Oracle2(AggregatorV3Interface(address(aggregator)), AggregatorV3Interface(address(0)), 18, 0);
74-
aggregator.setAnwser(-1);
73+
OracleTwoFeeds oracle =
74+
new OracleTwoFeeds(AggregatorV3Interface(address(aggregator)), AggregatorV3Interface(address(0)), 18, 0);
75+
aggregator.setAnwser(price);
7576
vm.expectRevert(bytes(ErrorsLib.NEGATIVE_ANSWER));
7677
oracle.price();
7778
}

0 commit comments

Comments
 (0)