Skip to content

Commit

Permalink
Merge pull request #52 from morpho-org/post-cantina
Browse files Browse the repository at this point in the history
Post cantina
  • Loading branch information
MerlinEgalite authored Dec 26, 2023
2 parents ac9b8ba + 0c6815f commit 6941f06
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/morpho-blue
Submodule morpho-blue updated 63 files
+51 −0 .github/workflows/certora.yml
+1 −1 .github/workflows/foundry.yml
+4 −0 .gitignore
+1 −1 README.md
+389 −0 certora/LICENSE
+287 −0 certora/README.md
+14 −0 certora/confs/AccrueInterest.conf
+9 −0 certora/confs/AssetsAccounting.conf
+9 −0 certora/confs/ConsistentState.conf
+13 −0 certora/confs/ExactMath.conf
+13 −0 certora/confs/Health.conf
+9 −0 certora/confs/LibSummary.conf
+9 −0 certora/confs/Liveness.conf
+14 −0 certora/confs/RatioMath.conf
+12 −0 certora/confs/Reentrancy.conf
+9 −0 certora/confs/Reverts.conf
+12 −0 certora/confs/Transfer.conf
+48 −0 certora/dispatch/ERC20NoRevert.sol
+42 −0 certora/dispatch/ERC20Standard.sol
+45 −0 certora/dispatch/ERC20USDT.sol
+6 −0 certora/gambit.conf
+92 −0 certora/harness/MorphoHarness.sol
+17 −0 certora/harness/MorphoInternalAccess.sol
+35 −0 certora/harness/TransferHarness.sol
+138 −0 certora/specs/AccrueInterest.spec
+126 −0 certora/specs/AssetsAccounting.spec
+294 −0 certora/specs/ConsistentState.spec
+123 −0 certora/specs/ExactMath.spec
+108 −0 certora/specs/Health.spec
+26 −0 certora/specs/LibSummary.spec
+386 −0 certora/specs/Liveness.spec
+184 −0 certora/specs/RatioMath.spec
+61 −0 certora/specs/Reentrancy.spec
+179 −0 certora/specs/Reverts.spec
+82 −0 certora/specs/Transfer.spec
+1 −1 foundry.toml
+1 −1 lib/forge-std
+48 −34 src/Morpho.sol
+3 −2 src/interfaces/IIrm.sol
+17 −14 src/interfaces/IMorpho.sol
+3 −0 src/libraries/ErrorsLib.sol
+10 −7 src/libraries/EventsLib.sol
+4 −3 src/libraries/SafeTransferLib.sol
+3 −0 src/libraries/SharesMathLib.sol
+1 −1 src/libraries/UtilsLib.sol
+6 −7 src/libraries/periphery/MorphoBalancesLib.sol
+9 −7 test/forge/BaseTest.sol
+1 −1 test/forge/helpers/SigUtils.sol
+12 −0 test/forge/integration/AccrueInterestIntegrationTest.sol
+17 −1 test/forge/integration/AuthorizationIntegrationTest.sol
+3 −3 test/forge/integration/BorrowIntegrationTest.sol
+5 −0 test/forge/integration/CallbacksIntegrationTest.sol
+22 −20 test/forge/integration/CreateMarketIntegrationTest.sol
+66 −4 test/forge/integration/LiquidateIntegrationTest.sol
+3 −2 test/forge/integration/OnlyOwnerIntegrationTest.sol
+12 −0 test/forge/integration/SupplyCollateralIntegrationTest.sol
+12 −0 test/forge/integration/SupplyIntegrationTest.sol
+1 −1 test/forge/integration/WithdrawCollateralIntegrationTest.sol
+5 −3 test/forge/invariant/MorphoInvariantTest.sol
+14 −0 test/forge/libraries/SafeTransferLibTest.sol
+31 −1 test/hardhat/Morpho.spec.ts
+0 −288 test/morpho_tests.tree
+1 −1 tsconfig.json
28 changes: 18 additions & 10 deletions src/ChainlinkOracle.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -12,27 +13,32 @@ import {Math} from "../lib/openzeppelin-contracts/contracts/utils/math/Math.sol"
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @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 */
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/AggregatorV3Interface.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// 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.
/// https://github.com/smartcontractkit/chainlink/blob/master/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol
interface AggregatorV3Interface {
function decimals() external view returns (uint8);

Expand Down
33 changes: 33 additions & 0 deletions src/interfaces/IChainlinkOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

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 [email protected]
/// @notice Interface of ChainlinkOracle.
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);
}
2 changes: 1 addition & 1 deletion src/interfaces/IERC4626.sol
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
7 changes: 4 additions & 3 deletions test/ChainlinkOracleTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 6941f06

Please sign in to comment.