Skip to content

Commit

Permalink
refactor: more coherent file names
Browse files Browse the repository at this point in the history
  • Loading branch information
QGarchery committed Oct 9, 2023
1 parent f72e33f commit 08373a0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/ChainlinkOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]
/// @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.
Expand All @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/interfaces/ERC4626Interface.sol
Original file line number Diff line number Diff line change
@@ -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);
}
15 changes: 4 additions & 11 deletions src/libraries/VaultDataFeedLib.sol → src/libraries/VaultLib.sol
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
// 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 [email protected]
/// @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);
}

/// @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();
Expand Down
4 changes: 2 additions & 2 deletions test/ChainlinkOracleTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 08373a0

Please sign in to comment.