From 08373a0606a368edba3356ebf05c703c760eda0e Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Mon, 9 Oct 2023 11:37:29 +0200 Subject: [PATCH] refactor: more coherent file names --- src/ChainlinkOracle.sol | 8 ++++---- src/interfaces/ERC4626Interface.sol | 7 +++++++ .../{VaultDataFeedLib.sol => VaultLib.sol} | 15 ++++----------- test/ChainlinkOracleTest.sol | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 src/interfaces/ERC4626Interface.sol rename src/libraries/{VaultDataFeedLib.sol => VaultLib.sol} (60%) diff --git a/src/ChainlinkOracle.sol b/src/ChainlinkOracle.sol index 180e1c4..bbe9063 100644 --- a/src/ChainlinkOracle.sol +++ b/src/ChainlinkOracle.sol @@ -4,20 +4,20 @@ pragma solidity 0.8.19; import {IOracle} from "morpho-blue/interfaces/IOracle.sol"; import {AggregatorV3Interface, ChainlinkDataFeedLib} from "./libraries/ChainlinkDataFeedLib.sol"; -import {ERC4626, VaultDataFeedLib} from "./libraries/VaultDataFeedLib.sol"; +import {ERC4626Interface, VaultLib} from "./libraries/VaultLib.sol"; /// @title ChainlinkOracle /// @author Morpho Labs /// @custom:contact security@morpho.org /// @notice Morpho Blue oracle using Chainlink-compliant feeds. contract ChainlinkOracle is IOracle { - using VaultDataFeedLib for ERC4626; + using VaultLib for ERC4626Interface; using ChainlinkDataFeedLib for AggregatorV3Interface; /* IMMUTABLES */ /// @notice Vault. - ERC4626 public immutable VAULT; + ERC4626Interface public immutable VAULT; /// @notice Vault decimals. uint256 public immutable VAULT_DECIMALS; /// @notice First base feed. @@ -41,7 +41,7 @@ contract ChainlinkOracle is IOracle { /// @param baseTokenDecimals Base token decimals. /// @param quoteTokenDecimals Quote token decimals. constructor( - ERC4626 vault, + ERC4626Interface vault, AggregatorV3Interface baseFeed1, AggregatorV3Interface baseFeed2, AggregatorV3Interface quoteFeed1, diff --git a/src/interfaces/ERC4626Interface.sol b/src/interfaces/ERC4626Interface.sol new file mode 100644 index 0000000..fa16d3d --- /dev/null +++ b/src/interfaces/ERC4626Interface.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.0; + +interface ERC4626Interface { + function convertToAssets(uint256) external view returns (uint256); + function decimals() external view returns (uint256); +} diff --git a/src/libraries/VaultDataFeedLib.sol b/src/libraries/VaultLib.sol similarity index 60% rename from src/libraries/VaultDataFeedLib.sol rename to src/libraries/VaultLib.sol index ba54ddb..86f9118 100644 --- a/src/libraries/VaultDataFeedLib.sol +++ b/src/libraries/VaultLib.sol @@ -1,23 +1,16 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; -import {AggregatorV3Interface} from "../interfaces/AggregatorV3Interface.sol"; - -import {ErrorsLib} from "./ErrorsLib.sol"; - -interface ERC4626 { - function convertToAssets(uint256) external view returns (uint256); - function decimals() external view returns (uint256); -} +import {ERC4626Interface} from "../interfaces/ERC4626Interface.sol"; /// @title ChainlinkDataFeedLib /// @author Morpho Labs /// @custom:contact security@morpho.org /// @notice Library exposing functions to interact with a Chainlink-compliant feed. -library VaultDataFeedLib { +library VaultLib { /// @dev Converts `shares` into the corresponding assets on the `vault`. /// @dev When `vault` is the address zero, returns 1. - function getAssets(ERC4626 vault, uint256 shares) internal view returns (uint256) { + function getAssets(ERC4626Interface vault, uint256 shares) internal view returns (uint256) { if (address(vault) == address(0)) return 1; return vault.convertToAssets(shares); @@ -25,7 +18,7 @@ library VaultDataFeedLib { /// @dev Returns the number of decimals of a `vault`, seen as an ERC20. /// @dev When `vault` is the address zero, returns 0. - function getDecimals(ERC4626 vault) internal view returns (uint256) { + function getDecimals(ERC4626Interface vault) internal view returns (uint256) { if (address(vault) == address(0)) return 0; return vault.decimals(); diff --git a/test/ChainlinkOracleTest.sol b/test/ChainlinkOracleTest.sol index 4119ec5..64c6fec 100644 --- a/test/ChainlinkOracleTest.sol +++ b/test/ChainlinkOracleTest.sol @@ -23,8 +23,8 @@ AggregatorV3Interface constant ethUsdFeed = AggregatorV3Interface(0x5f4eC3Df9cbd // 18 decimals of precision AggregatorV3Interface constant daiEthFeed = AggregatorV3Interface(0x773616E4d11A78F511299002da57A0a94577F1f4); -ERC4626 constant vaultZero = ERC4626(address(0)); -ERC4626 constant sDaiVault = ERC4626(0x83F20F44975D03b1b09e64809B757c47f942BEeA); +ERC4626Interface constant vaultZero = ERC4626Interface(address(0)); +ERC4626Interface constant sDaiVault = ERC4626Interface(0x83F20F44975D03b1b09e64809B757c47f942BEeA); contract FakeAggregator { int256 public answer;