From 22bebcc629aa5b561ae326b4ab28037b2e86c4f4 Mon Sep 17 00:00:00 2001 From: Jean-Grimal <83286814+Jean-Grimal@users.noreply.github.com> Date: Tue, 9 Apr 2024 17:10:00 +0200 Subject: [PATCH] refactor: only use MinimalAggregatorV3Interface --- .../interfaces/IStEth.sol | 0 .../MinimalAggregatorV3Interface.sol | 0 .../MorphoChainlinkOracleV2.sol | 20 ++++++++--------- .../MorphoChainlinkOracleV2Factory.sol | 10 ++++----- .../interfaces/AggregatorV3Interface.sol | 22 ------------------- .../interfaces/IMorphoChainlinkOracleV2.sol | 10 ++++----- .../IMorphoChainlinkOracleV2Factory.sol | 10 ++++----- .../libraries/ChainlinkDataFeedLib.sol | 6 ++--- ...stEthStEthExchangeRateChainlinkAdapter.sol | 4 ++-- 9 files changed, 30 insertions(+), 52 deletions(-) rename src/{wsteth-exchange-rate-adapter => }/interfaces/IStEth.sol (100%) rename src/{wsteth-exchange-rate-adapter => }/interfaces/MinimalAggregatorV3Interface.sol (100%) delete mode 100644 src/morpho-chainlink/interfaces/AggregatorV3Interface.sol diff --git a/src/wsteth-exchange-rate-adapter/interfaces/IStEth.sol b/src/interfaces/IStEth.sol similarity index 100% rename from src/wsteth-exchange-rate-adapter/interfaces/IStEth.sol rename to src/interfaces/IStEth.sol diff --git a/src/wsteth-exchange-rate-adapter/interfaces/MinimalAggregatorV3Interface.sol b/src/interfaces/MinimalAggregatorV3Interface.sol similarity index 100% rename from src/wsteth-exchange-rate-adapter/interfaces/MinimalAggregatorV3Interface.sol rename to src/interfaces/MinimalAggregatorV3Interface.sol diff --git a/src/morpho-chainlink/MorphoChainlinkOracleV2.sol b/src/morpho-chainlink/MorphoChainlinkOracleV2.sol index 48f8298..6b5386c 100644 --- a/src/morpho-chainlink/MorphoChainlinkOracleV2.sol +++ b/src/morpho-chainlink/MorphoChainlinkOracleV2.sol @@ -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 @@ -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 */ @@ -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; @@ -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 diff --git a/src/morpho-chainlink/MorphoChainlinkOracleV2Factory.sol b/src/morpho-chainlink/MorphoChainlinkOracleV2Factory.sol index c2b51dc..54d5b8f 100644 --- a/src/morpho-chainlink/MorphoChainlinkOracleV2Factory.sol +++ b/src/morpho-chainlink/MorphoChainlinkOracleV2Factory.sol @@ -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"; @@ -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) { diff --git a/src/morpho-chainlink/interfaces/AggregatorV3Interface.sol b/src/morpho-chainlink/interfaces/AggregatorV3Interface.sol deleted file mode 100644 index 481516f..0000000 --- a/src/morpho-chainlink/interfaces/AggregatorV3Interface.sol +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.5.0; - -/// @dev From -/// https://github.com/smartcontractkit/chainlink/blob/master/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol -interface AggregatorV3Interface { - function decimals() external view returns (uint8); - - function description() external view returns (string memory); - - function version() external view returns (uint256); - - function getRoundData(uint80 _roundId) - external - view - returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound); - - function latestRoundData() - external - view - returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound); -} diff --git a/src/morpho-chainlink/interfaces/IMorphoChainlinkOracleV2.sol b/src/morpho-chainlink/interfaces/IMorphoChainlinkOracleV2.sol index 1e65aae..1e0f618 100644 --- a/src/morpho-chainlink/interfaces/IMorphoChainlinkOracleV2.sol +++ b/src/morpho-chainlink/interfaces/IMorphoChainlinkOracleV2.sol @@ -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 @@ -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); diff --git a/src/morpho-chainlink/interfaces/IMorphoChainlinkOracleV2Factory.sol b/src/morpho-chainlink/interfaces/IMorphoChainlinkOracleV2Factory.sol index 64f8e6e..90bd1b0 100644 --- a/src/morpho-chainlink/interfaces/IMorphoChainlinkOracleV2Factory.sol +++ b/src/morpho-chainlink/interfaces/IMorphoChainlinkOracleV2Factory.sol @@ -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 @@ -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); diff --git a/src/morpho-chainlink/libraries/ChainlinkDataFeedLib.sol b/src/morpho-chainlink/libraries/ChainlinkDataFeedLib.sol index 10da74e..be057f9 100644 --- a/src/morpho-chainlink/libraries/ChainlinkDataFeedLib.sol +++ b/src/morpho-chainlink/libraries/ChainlinkDataFeedLib.sol @@ -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"; @@ -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(); @@ -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(); diff --git a/src/wsteth-exchange-rate-adapter/WstEthStEthExchangeRateChainlinkAdapter.sol b/src/wsteth-exchange-rate-adapter/WstEthStEthExchangeRateChainlinkAdapter.sol index 6341c13..0df65f2 100644 --- a/src/wsteth-exchange-rate-adapter/WstEthStEthExchangeRateChainlinkAdapter.sol +++ b/src/wsteth-exchange-rate-adapter/WstEthStEthExchangeRateChainlinkAdapter.sol @@ -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