From 875667c01c78b7b2423ccfe5d402c39cd75f6d3f Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Wed, 29 Nov 2023 12:09:49 +0100 Subject: [PATCH 1/8] feat(ifc): add interfaces --- lib/morpho-blue | 2 +- src/ChainlinkOracle.sol | 28 ++++++++++++++++++---------- src/interfaces/IChainlinkOracle.sol | 29 +++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 src/interfaces/IChainlinkOracle.sol diff --git a/lib/morpho-blue b/lib/morpho-blue index f463e40..82884a6 160000 --- a/lib/morpho-blue +++ b/lib/morpho-blue @@ -1 +1 @@ -Subproject commit f463e40f776acd0f26d0d380b51cfd02949c8c23 +Subproject commit 82884a63c6a108b69f2617dbc01be8d09ba2924d diff --git a/src/ChainlinkOracle.sol b/src/ChainlinkOracle.sol index 9f36cdc..f020ca2 100644 --- a/src/ChainlinkOracle.sol +++ b/src/ChainlinkOracle.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity 0.8.21; +import {IChainlinkOracle} from "./interfaces/IChainlinkOracle.sol"; import {IOracle} from "../lib/morpho-blue/src/interfaces/IOracle.sol"; import {AggregatorV3Interface, ChainlinkDataFeedLib} from "./libraries/ChainlinkDataFeedLib.sol"; @@ -12,27 +13,32 @@ import {Math} from "../lib/openzeppelin-contracts/contracts/utils/math/Math.sol" /// @author Morpho Labs /// @custom:contact security@morpho.org /// @notice Morpho Blue oracle using Chainlink-compliant feeds. -contract ChainlinkOracle is IOracle { +contract ChainlinkOracle is IChainlinkOracle { using Math for uint256; using VaultLib for IERC4626; using ChainlinkDataFeedLib for AggregatorV3Interface; /* IMMUTABLES */ - /// @notice Vault. + /// @inheritdoc IChainlinkOracle IERC4626 public immutable VAULT; - /// @notice Vault conversion sample. The sample amount of shares used to convert to the underlying asset. - /// @notice Should be chosen such that converting `VAULT_CONVERSION_SAMPLE` to assets has enough precision. + + /// @inheritdoc IChainlinkOracle uint256 public immutable VAULT_CONVERSION_SAMPLE; - /// @notice First base feed. + + /// @inheritdoc IChainlinkOracle AggregatorV3Interface public immutable BASE_FEED_1; - /// @notice Second base feed. + + /// @inheritdoc IChainlinkOracle AggregatorV3Interface public immutable BASE_FEED_2; - /// @notice First quote feed. + + /// @inheritdoc IChainlinkOracle AggregatorV3Interface public immutable QUOTE_FEED_1; - /// @notice Second quote feed. + + /// @inheritdoc IChainlinkOracle AggregatorV3Interface public immutable QUOTE_FEED_2; - /// @notice Price scale factor, computed at contract creation. + + /// @inheritdoc IChainlinkOracle uint256 public immutable SCALE_FACTOR; /* CONSTRUCTOR */ @@ -50,7 +56,9 @@ contract ChainlinkOracle is IOracle { /// @param baseFeed2 Second base feed. Pass address zero if the price = 1. /// @param quoteFeed1 First quote feed. Pass address zero if the price = 1. /// @param quoteFeed2 Second quote feed. Pass address zero if the price = 1. - /// @param vaultConversionSample Vault conversion sample. Pass 1 if the oracle does not use a vault. + /// @param vaultConversionSample The sample amount of vault shares used to convert to the underlying asset. + /// Pass 1 if the oracle does not use a vault. Should be chosen such that converting `vaultConversionSample` to + /// assets has enough precision. /// @param baseTokenDecimals Base token decimals. /// @param quoteTokenDecimals Quote token decimals. constructor( diff --git a/src/interfaces/IChainlinkOracle.sol b/src/interfaces/IChainlinkOracle.sol new file mode 100644 index 0000000..4a4bba1 --- /dev/null +++ b/src/interfaces/IChainlinkOracle.sol @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +pragma solidity ^0.8.0; + +import {IERC4626} from "./IERC4626.sol"; +import {AggregatorV3Interface} from "./AggregatorV3Interface.sol"; +import {IOracle} from "../../lib/morpho-blue/src/interfaces/IOracle.sol"; + +interface IChainlinkOracle is IOracle { + /// @notice Returns the address of the ERC4626 vault. + function VAULT() external view returns (IERC4626); + + /// @notice Returns the vault conversion sample. + function VAULT_CONVERSION_SAMPLE() external view returns (uint256); + + /// @notice Returns the address of the first Chainlink base feed. + function BASE_FEED_1() external view returns (AggregatorV3Interface); + + /// @notice Returns the address of the second Chainlink base feed. + function BASE_FEED_2() external view returns (AggregatorV3Interface); + + /// @notice Returns the address of the first Chainlink quote feed. + function QUOTE_FEED_1() external view returns (AggregatorV3Interface); + + /// @notice Returns the address of the second Chainlink quote feed. + function QUOTE_FEED_2() external view returns (AggregatorV3Interface); + + /// @notice Returns the price scale factor, calculated at contract creation. + function SCALE_FACTOR() external view returns (uint256); +} From bd4717085d74e66573cf443748c0b2a7deba7093 Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Wed, 29 Nov 2023 12:20:24 +0100 Subject: [PATCH 2/8] refactor(fmt): format trests --- lib/morpho-blue | 2 +- test/ChainlinkOracleTest.sol | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/morpho-blue b/lib/morpho-blue index 82884a6..f463e40 160000 --- a/lib/morpho-blue +++ b/lib/morpho-blue @@ -1 +1 @@ -Subproject commit 82884a63c6a108b69f2617dbc01be8d09ba2924d +Subproject commit f463e40f776acd0f26d0d380b51cfd02949c8c23 diff --git a/test/ChainlinkOracleTest.sol b/test/ChainlinkOracleTest.sol index 42f57b9..1460244 100644 --- a/test/ChainlinkOracleTest.sol +++ b/test/ChainlinkOracleTest.sol @@ -57,7 +57,7 @@ contract ChainlinkOracleTest is Test { } function testOracleWbtcEth() public { - ChainlinkOracle oracle = new ChainlinkOracle(vaultZero,wBtcBtcFeed, btcEthFeed, feedZero, feedZero, 1, 8, 18); + ChainlinkOracle oracle = new ChainlinkOracle(vaultZero, wBtcBtcFeed, btcEthFeed, feedZero, feedZero, 1, 8, 18); (, int256 firstBaseAnswer,,,) = wBtcBtcFeed.latestRoundData(); (, int256 secondBaseAnswer,,,) = btcEthFeed.latestRoundData(); assertEq(oracle.price(), (uint256(firstBaseAnswer) * uint256(secondBaseAnswer) * 10 ** (36 + 18 - 8 - 8 - 18))); @@ -98,8 +98,9 @@ contract ChainlinkOracleTest is Test { function testNegativeAnswer(int256 price) public { price = bound(price, type(int256).min, -1); ChainlinkAggregatorMock aggregator = new ChainlinkAggregatorMock(); - ChainlinkOracle oracle = - new ChainlinkOracle(vaultZero, AggregatorV3Interface(address(aggregator)), feedZero, feedZero, feedZero, 1, 18, 0); + ChainlinkOracle oracle = new ChainlinkOracle( + vaultZero, AggregatorV3Interface(address(aggregator)), feedZero, feedZero, feedZero, 1, 18, 0 + ); aggregator.setAnwser(price); vm.expectRevert(bytes(ErrorsLib.NEGATIVE_ANSWER)); oracle.price(); From 467d38072dd2b6487c1d807f861eb5b371b6fcb3 Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Wed, 29 Nov 2023 16:08:01 +0100 Subject: [PATCH 3/8] fix(ifc): lower pragma --- src/interfaces/AggregatorV3Interface.sol | 2 +- src/interfaces/IChainlinkOracle.sol | 2 +- src/interfaces/IERC4626.sol | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/interfaces/AggregatorV3Interface.sol b/src/interfaces/AggregatorV3Interface.sol index e12ac3e..33dd838 100644 --- a/src/interfaces/AggregatorV3Interface.sol +++ b/src/interfaces/AggregatorV3Interface.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; +pragma solidity >=0.5.0; /// @dev From /// https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol. diff --git a/src/interfaces/IChainlinkOracle.sol b/src/interfaces/IChainlinkOracle.sol index 4a4bba1..dba1eca 100644 --- a/src/interfaces/IChainlinkOracle.sol +++ b/src/interfaces/IChainlinkOracle.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-or-later -pragma solidity ^0.8.0; +pragma solidity >=0.5.0; import {IERC4626} from "./IERC4626.sol"; import {AggregatorV3Interface} from "./AggregatorV3Interface.sol"; diff --git a/src/interfaces/IERC4626.sol b/src/interfaces/IERC4626.sol index 224b4cd..b848fd6 100644 --- a/src/interfaces/IERC4626.sol +++ b/src/interfaces/IERC4626.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-or-later -pragma solidity ^0.8.0; +pragma solidity >=0.5.0; interface IERC4626 { function convertToAssets(uint256) external view returns (uint256); From 32235e5b23594c7ef6430dcd44450c5dd81e11da Mon Sep 17 00:00:00 2001 From: Jean-Grimal Date: Tue, 12 Dec 2023 19:29:26 +0100 Subject: [PATCH 4/8] fix: update chainlink aggregator interface link --- src/interfaces/AggregatorV3Interface.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaces/AggregatorV3Interface.sol b/src/interfaces/AggregatorV3Interface.sol index 33dd838..67bb071 100644 --- a/src/interfaces/AggregatorV3Interface.sol +++ b/src/interfaces/AggregatorV3Interface.sol @@ -2,7 +2,7 @@ pragma solidity >=0.5.0; /// @dev From -/// https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol. +/// https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol. interface AggregatorV3Interface { function decimals() external view returns (uint8); From b56254eb4a56824c9923d2e2c3570b4d7f69c8ac Mon Sep 17 00:00:00 2001 From: Jean-Grimal <83286814+Jean-Grimal@users.noreply.github.com> Date: Wed, 13 Dec 2023 09:42:00 +0100 Subject: [PATCH 5/8] Update src/interfaces/AggregatorV3Interface.sol Co-authored-by: Romain Milon Signed-off-by: Jean-Grimal <83286814+Jean-Grimal@users.noreply.github.com> --- src/interfaces/AggregatorV3Interface.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaces/AggregatorV3Interface.sol b/src/interfaces/AggregatorV3Interface.sol index 67bb071..a892379 100644 --- a/src/interfaces/AggregatorV3Interface.sol +++ b/src/interfaces/AggregatorV3Interface.sol @@ -2,7 +2,7 @@ pragma solidity >=0.5.0; /// @dev From -/// https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol. +/// https://github.com/smartcontractkit/chainlink/blob/master/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol interface AggregatorV3Interface { function decimals() external view returns (uint8); From 753c3502735520079e988c4e4c73487f37c3e232 Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Wed, 20 Dec 2023 10:46:54 +0100 Subject: [PATCH 6/8] docs(ifc): add natspecs --- src/interfaces/IChainlinkOracle.sol | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/interfaces/IChainlinkOracle.sol b/src/interfaces/IChainlinkOracle.sol index dba1eca..cbe5fb3 100644 --- a/src/interfaces/IChainlinkOracle.sol +++ b/src/interfaces/IChainlinkOracle.sol @@ -5,6 +5,10 @@ import {IERC4626} from "./IERC4626.sol"; import {AggregatorV3Interface} from "./AggregatorV3Interface.sol"; import {IOracle} from "../../lib/morpho-blue/src/interfaces/IOracle.sol"; +/// @title IChainlinkOracle +/// @author Morpho Labs +/// @custom:contact security@morpho.org +/// @notice Interface exposed by the ChainlinkOracle. interface IChainlinkOracle is IOracle { /// @notice Returns the address of the ERC4626 vault. function VAULT() external view returns (IERC4626); From 31862674cf596d145b69807f4dad7f7abdbee7ec Mon Sep 17 00:00:00 2001 From: Merlin Egalite <44097430+MerlinEgalite@users.noreply.github.com> Date: Thu, 21 Dec 2023 09:04:32 +0100 Subject: [PATCH 7/8] docs: small change Co-authored-by: Quentin Garchery Signed-off-by: Merlin Egalite <44097430+MerlinEgalite@users.noreply.github.com> --- src/interfaces/IChainlinkOracle.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaces/IChainlinkOracle.sol b/src/interfaces/IChainlinkOracle.sol index cbe5fb3..8f4162a 100644 --- a/src/interfaces/IChainlinkOracle.sol +++ b/src/interfaces/IChainlinkOracle.sol @@ -8,7 +8,7 @@ import {IOracle} from "../../lib/morpho-blue/src/interfaces/IOracle.sol"; /// @title IChainlinkOracle /// @author Morpho Labs /// @custom:contact security@morpho.org -/// @notice Interface exposed by the ChainlinkOracle. +/// @notice Interface of ChainlinkOracle. interface IChainlinkOracle is IOracle { /// @notice Returns the address of the ERC4626 vault. function VAULT() external view returns (IERC4626); From a390f33ce3c8e5e0743901f72f6996c9b2b0e1ce Mon Sep 17 00:00:00 2001 From: MerlinEgalite Date: Sat, 23 Dec 2023 09:33:18 +0100 Subject: [PATCH 8/8] chore: update morpho-blue --- lib/morpho-blue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/morpho-blue b/lib/morpho-blue index f463e40..55d2d99 160000 --- a/lib/morpho-blue +++ b/lib/morpho-blue @@ -1 +1 @@ -Subproject commit f463e40f776acd0f26d0d380b51cfd02949c8c23 +Subproject commit 55d2d99304fb3fb930c688462ae2ccabb1d533ad