-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
17 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
src/libraries/VaultDataFeedLib.sol → src/libraries/VaultLib.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters