Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use MinimalAggregatorV3Interface #97

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we decided to use 2 folders so that it avoids the risk of modifying the source code when working on a new contract. Here this is making it possible again, because one can be tempted to modify IStEth for a new oracle that needs other data from stEth.

Does it make sense here to share the interfaces ? Not sure what we gain, but at the same time adding function signatures to the interface should not be a problem at all

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

But I remember we decided to use the minimal interface because some functions were useless in the standard interface.

Right now, when integrators fork the repo to build a new oracle they use the standard interface because it's in morpho-chainlink folder and, thus, implement useless functions (eg Angle, fxusd, etc.). I would recommend to at least change the standard interface to the minimal in the folder mentioned earlier.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jean-Grimal can you make the change please

File renamed without changes.
20 changes: 10 additions & 10 deletions src/morpho-chainlink/MorphoChainlinkOracleV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {IMorphoChainlinkOracleV2} from "./interfaces/IMorphoChainlinkOracleV2.so
import {ErrorsLib} from "./libraries/ErrorsLib.sol";
import {IERC4626, VaultLib} from "./libraries/VaultLib.sol";
import {Math} from "../../lib/openzeppelin-contracts/contracts/utils/math/Math.sol";
import {AggregatorV3Interface, ChainlinkDataFeedLib} from "./libraries/ChainlinkDataFeedLib.sol";
import {MinimalAggregatorV3Interface, ChainlinkDataFeedLib} from "./libraries/ChainlinkDataFeedLib.sol";

/// @title MorphoChainlinkOracleV2
/// @author Morpho Labs
Expand All @@ -16,7 +16,7 @@ import {AggregatorV3Interface, ChainlinkDataFeedLib} from "./libraries/Chainlink
contract MorphoChainlinkOracleV2 is IMorphoChainlinkOracleV2 {
using Math for uint256;
using VaultLib for IERC4626;
using ChainlinkDataFeedLib for AggregatorV3Interface;
using ChainlinkDataFeedLib for MinimalAggregatorV3Interface;

/* IMMUTABLES */

Expand All @@ -33,16 +33,16 @@ contract MorphoChainlinkOracleV2 is IMorphoChainlinkOracleV2 {
uint256 public immutable QUOTE_VAULT_CONVERSION_SAMPLE;

/// @inheritdoc IMorphoChainlinkOracleV2
AggregatorV3Interface public immutable BASE_FEED_1;
MinimalAggregatorV3Interface public immutable BASE_FEED_1;

/// @inheritdoc IMorphoChainlinkOracleV2
AggregatorV3Interface public immutable BASE_FEED_2;
MinimalAggregatorV3Interface public immutable BASE_FEED_2;

/// @inheritdoc IMorphoChainlinkOracleV2
AggregatorV3Interface public immutable QUOTE_FEED_1;
MinimalAggregatorV3Interface public immutable QUOTE_FEED_1;

/// @inheritdoc IMorphoChainlinkOracleV2
AggregatorV3Interface public immutable QUOTE_FEED_2;
MinimalAggregatorV3Interface public immutable QUOTE_FEED_2;

/// @inheritdoc IMorphoChainlinkOracleV2
uint256 public immutable SCALE_FACTOR;
Expand Down Expand Up @@ -73,13 +73,13 @@ contract MorphoChainlinkOracleV2 is IMorphoChainlinkOracleV2 {
constructor(
IERC4626 baseVault,
uint256 baseVaultConversionSample,
AggregatorV3Interface baseFeed1,
AggregatorV3Interface baseFeed2,
MinimalAggregatorV3Interface baseFeed1,
MinimalAggregatorV3Interface baseFeed2,
uint256 baseTokenDecimals,
IERC4626 quoteVault,
uint256 quoteVaultConversionSample,
AggregatorV3Interface quoteFeed1,
AggregatorV3Interface quoteFeed2,
MinimalAggregatorV3Interface quoteFeed1,
MinimalAggregatorV3Interface quoteFeed2,
uint256 quoteTokenDecimals
) {
// The ERC4626 vault parameters are used to price their respective conversion samples of their respective
Expand Down
10 changes: 5 additions & 5 deletions src/morpho-chainlink/MorphoChainlinkOracleV2Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.21;

import {IMorphoChainlinkOracleV2} from "./interfaces/IMorphoChainlinkOracleV2.sol";
import {IMorphoChainlinkOracleV2Factory} from "./interfaces/IMorphoChainlinkOracleV2Factory.sol";
import {AggregatorV3Interface} from "./libraries/ChainlinkDataFeedLib.sol";
import {MinimalAggregatorV3Interface} from "./libraries/ChainlinkDataFeedLib.sol";
import {IERC4626} from "./libraries/VaultLib.sol";

import {MorphoChainlinkOracleV2} from "./MorphoChainlinkOracleV2.sol";
Expand All @@ -24,13 +24,13 @@ contract MorphoChainlinkOracleV2Factory is IMorphoChainlinkOracleV2Factory {
function createMorphoChainlinkOracleV2(
IERC4626 baseVault,
uint256 baseVaultConversionSample,
AggregatorV3Interface baseFeed1,
AggregatorV3Interface baseFeed2,
MinimalAggregatorV3Interface baseFeed1,
MinimalAggregatorV3Interface baseFeed2,
uint256 baseTokenDecimals,
IERC4626 quoteVault,
uint256 quoteVaultConversionSample,
AggregatorV3Interface quoteFeed1,
AggregatorV3Interface quoteFeed2,
MinimalAggregatorV3Interface quoteFeed1,
MinimalAggregatorV3Interface quoteFeed2,
uint256 quoteTokenDecimals,
bytes32 salt
) external returns (MorphoChainlinkOracleV2 oracle) {
Expand Down
22 changes: 0 additions & 22 deletions src/morpho-chainlink/interfaces/AggregatorV3Interface.sol

This file was deleted.

10 changes: 5 additions & 5 deletions src/morpho-chainlink/interfaces/IMorphoChainlinkOracleV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.5.0;

import {IERC4626} from "./IERC4626.sol";
import {IOracle} from "../../../lib/morpho-blue/src/interfaces/IOracle.sol";
import {AggregatorV3Interface} from "./AggregatorV3Interface.sol";
import {MinimalAggregatorV3Interface} from "../../interfaces/MinimalAggregatorV3Interface.sol";

/// @title IMorphoChainlinkOracleV2
/// @author Morpho Labs
Expand All @@ -23,16 +23,16 @@ interface IMorphoChainlinkOracleV2 is IOracle {
function QUOTE_VAULT_CONVERSION_SAMPLE() external view returns (uint256);

/// @notice Returns the address of the first base feed.
function BASE_FEED_1() external view returns (AggregatorV3Interface);
function BASE_FEED_1() external view returns (MinimalAggregatorV3Interface);

/// @notice Returns the address of the second base feed.
function BASE_FEED_2() external view returns (AggregatorV3Interface);
function BASE_FEED_2() external view returns (MinimalAggregatorV3Interface);

/// @notice Returns the address of the first quote feed.
function QUOTE_FEED_1() external view returns (AggregatorV3Interface);
function QUOTE_FEED_1() external view returns (MinimalAggregatorV3Interface);

/// @notice Returns the address of the second quote feed.
function QUOTE_FEED_2() external view returns (AggregatorV3Interface);
function QUOTE_FEED_2() external view returns (MinimalAggregatorV3Interface);

/// @notice Returns the price scale factor, calculated at contract creation.
function SCALE_FACTOR() external view returns (uint256);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.5.0;

import {MorphoChainlinkOracleV2} from "../MorphoChainlinkOracleV2.sol";
import {IERC4626} from "../libraries/VaultLib.sol";
import {AggregatorV3Interface} from "../libraries/ChainlinkDataFeedLib.sol";
import {MinimalAggregatorV3Interface} from "../libraries/ChainlinkDataFeedLib.sol";

/// @title IMorphoChainlinkOracleV2Factory
/// @author Morpho Labs
Expand Down Expand Up @@ -43,13 +43,13 @@ interface IMorphoChainlinkOracleV2Factory {
function createMorphoChainlinkOracleV2(
IERC4626 baseVault,
uint256 baseVaultConversionSample,
AggregatorV3Interface baseFeed1,
AggregatorV3Interface baseFeed2,
MinimalAggregatorV3Interface baseFeed1,
MinimalAggregatorV3Interface baseFeed2,
uint256 baseTokenDecimals,
IERC4626 quoteVault,
uint256 quoteVaultConversionSample,
AggregatorV3Interface quoteFeed1,
AggregatorV3Interface quoteFeed2,
MinimalAggregatorV3Interface quoteFeed1,
MinimalAggregatorV3Interface quoteFeed2,
uint256 quoteTokenDecimals,
bytes32 salt
) external returns (MorphoChainlinkOracleV2 oracle);
Expand Down
6 changes: 3 additions & 3 deletions src/morpho-chainlink/libraries/ChainlinkDataFeedLib.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {AggregatorV3Interface} from "../interfaces/AggregatorV3Interface.sol";
import {MinimalAggregatorV3Interface} from "../../interfaces/MinimalAggregatorV3Interface.sol";

import {ErrorsLib} from "./ErrorsLib.sol";

Expand All @@ -17,7 +17,7 @@ library ChainlinkDataFeedLib {
/// - Staleness is not checked because it's assumed that the Chainlink feed keeps its promises on this.
/// - The price is not checked to be in the min/max bounds because it's assumed that the Chainlink feed keeps its
/// promises on this.
function getPrice(AggregatorV3Interface feed) internal view returns (uint256) {
function getPrice(MinimalAggregatorV3Interface feed) internal view returns (uint256) {
if (address(feed) == address(0)) return 1;

(, int256 answer,,,) = feed.latestRoundData();
Expand All @@ -28,7 +28,7 @@ library ChainlinkDataFeedLib {

/// @dev Returns the number of decimals of a `feed`.
/// @dev When `feed` is the address zero, returns 0.
function getDecimals(AggregatorV3Interface feed) internal view returns (uint256) {
function getDecimals(MinimalAggregatorV3Interface feed) internal view returns (uint256) {
if (address(feed) == address(0)) return 0;

return feed.decimals();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.21;

import {IStEth} from "./interfaces/IStEth.sol";
import {MinimalAggregatorV3Interface} from "./interfaces/MinimalAggregatorV3Interface.sol";
import {IStEth} from "../interfaces/IStEth.sol";
import {MinimalAggregatorV3Interface} from "../interfaces/MinimalAggregatorV3Interface.sol";

/// @title WstEthStEthExchangeRateChainlinkAdapter
/// @author Morpho Labs
Expand Down
2 changes: 1 addition & 1 deletion test/MorphoChainlinkOracleV2FactoryTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "../src/morpho-chainlink/MorphoChainlinkOracleV2Factory.sol";
import {ChainlinkDataFeedLib} from "../src/morpho-chainlink/libraries/ChainlinkDataFeedLib.sol";

contract ChainlinkOracleFactoryTest is Test {
using ChainlinkDataFeedLib for AggregatorV3Interface;
using ChainlinkDataFeedLib for MinimalAggregatorV3Interface;

MorphoChainlinkOracleV2Factory factory;

Expand Down
11 changes: 10 additions & 1 deletion test/MorphoChainlinkOracleV2Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ contract MorphoChainlinkOracleV2Test is Test {
price = bound(price, type(int256).min, -1);
ChainlinkAggregatorMock aggregator = new ChainlinkAggregatorMock();
MorphoChainlinkOracleV2 oracle = new MorphoChainlinkOracleV2(
vaultZero, 1, AggregatorV3Interface(address(aggregator)), feedZero, 18, vaultZero, 1, feedZero, feedZero, 0
vaultZero,
1,
MinimalAggregatorV3Interface(address(aggregator)),
feedZero,
18,
vaultZero,
1,
feedZero,
feedZero,
0
);
aggregator.setAnwser(price);
vm.expectRevert(bytes(ErrorsLib.NEGATIVE_ANSWER));
Expand Down
11 changes: 10 additions & 1 deletion test/WstEthStEthExchangeRateChainlinkAdapterTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ contract WstEthStEthExchangeRateChainlinkAdapterTest is Test {
require(block.chainid == 1, "chain isn't Ethereum");
adapter = new WstEthStEthExchangeRateChainlinkAdapter();
morphoOracle = new MorphoChainlinkOracleV2(
vaultZero, 1, AggregatorV3Interface(address(adapter)), feedZero, 18, vaultZero, 1, feedZero, feedZero, 18
vaultZero,
1,
MinimalAggregatorV3Interface(address(adapter)),
feedZero,
18,
vaultZero,
1,
feedZero,
feedZero,
18
);
}

Expand Down
28 changes: 18 additions & 10 deletions test/helpers/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,33 @@
pragma solidity ^0.8.0;

import {IERC4626} from "../../src/morpho-chainlink/interfaces/IERC4626.sol";
import {AggregatorV3Interface} from "../../src/morpho-chainlink/interfaces/AggregatorV3Interface.sol";
import {MinimalAggregatorV3Interface} from "../../src/interfaces/MinimalAggregatorV3Interface.sol";

AggregatorV3Interface constant feedZero = AggregatorV3Interface(address(0));
MinimalAggregatorV3Interface constant feedZero = MinimalAggregatorV3Interface(address(0));
// 8 decimals of precision
AggregatorV3Interface constant btcUsdFeed = AggregatorV3Interface(0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c);
MinimalAggregatorV3Interface constant btcUsdFeed =
MinimalAggregatorV3Interface(0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c);
// 8 decimals of precision
AggregatorV3Interface constant usdcUsdFeed = AggregatorV3Interface(0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6);
MinimalAggregatorV3Interface constant usdcUsdFeed =
MinimalAggregatorV3Interface(0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6);
// 18 decimals of precision
AggregatorV3Interface constant btcEthFeed = AggregatorV3Interface(0xdeb288F737066589598e9214E782fa5A8eD689e8);
MinimalAggregatorV3Interface constant btcEthFeed =
MinimalAggregatorV3Interface(0xdeb288F737066589598e9214E782fa5A8eD689e8);
// 8 decimals of precision
AggregatorV3Interface constant wBtcBtcFeed = AggregatorV3Interface(0xfdFD9C85aD200c506Cf9e21F1FD8dd01932FBB23);
MinimalAggregatorV3Interface constant wBtcBtcFeed =
MinimalAggregatorV3Interface(0xfdFD9C85aD200c506Cf9e21F1FD8dd01932FBB23);
// 18 decimals of precision
AggregatorV3Interface constant stEthEthFeed = AggregatorV3Interface(0x86392dC19c0b719886221c78AB11eb8Cf5c52812);
MinimalAggregatorV3Interface constant stEthEthFeed =
MinimalAggregatorV3Interface(0x86392dC19c0b719886221c78AB11eb8Cf5c52812);
// 18 decimals of precision
AggregatorV3Interface constant usdcEthFeed = AggregatorV3Interface(0x986b5E1e1755e3C2440e960477f25201B0a8bbD4);
MinimalAggregatorV3Interface constant usdcEthFeed =
MinimalAggregatorV3Interface(0x986b5E1e1755e3C2440e960477f25201B0a8bbD4);
// 8 decimals of precision
AggregatorV3Interface constant ethUsdFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
MinimalAggregatorV3Interface constant ethUsdFeed =
MinimalAggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
// 18 decimals of precision
AggregatorV3Interface constant daiEthFeed = AggregatorV3Interface(0x773616E4d11A78F511299002da57A0a94577F1f4);
MinimalAggregatorV3Interface constant daiEthFeed =
MinimalAggregatorV3Interface(0x773616E4d11A78F511299002da57A0a94577F1f4);

IERC4626 constant vaultZero = IERC4626(address(0));
IERC4626 constant sDaiVault = IERC4626(0x83F20F44975D03b1b09e64809B757c47f942BEeA);
Expand Down
Loading