From 343e1554965a77cd1f11830d3e62036aea9b388a Mon Sep 17 00:00:00 2001 From: 0xEinCodes <0xEinCodes@gmail.com> Date: Tue, 23 Jan 2024 16:12:42 -0600 Subject: [PATCH] Resolve audit fix G-1 w/ accrueInterest() --- .../MorphoBlueCollateralAdaptor.sol | 13 ---------- .../MorphoBlue/MorphoBlueDebtAdaptor.sol | 16 +----------- .../MorphoBlue/MorphoBlueHelperLogic.sol | 11 +++++--- .../MorphoBlue/MorphoBlueSupplyAdaptor.sol | 14 ---------- test/resources/AdaptorHelperFunctions.sol | 26 ++++++++++++------- .../MorphoBlue/MorphoBlueSupplyAdaptor.t.sol | 4 +-- 6 files changed, 27 insertions(+), 57 deletions(-) diff --git a/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueCollateralAdaptor.sol b/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueCollateralAdaptor.sol index 2b4d3abd4..680e011db 100644 --- a/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueCollateralAdaptor.sol +++ b/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueCollateralAdaptor.sol @@ -154,19 +154,6 @@ contract MorphoBlueCollateralAdaptor is BaseAdaptor, MorphoBlueHelperLogic { } } - /** - * @notice Allows a strategist to call `accrueInterest()` on a MB Market cellar is using. - * @dev A strategist might want to do this if a MB market has not been interacted with - * in a while, and the strategist does not plan on interacting with it during a - * rebalance. - * @dev Calling this can increase the share price during the rebalance, - * so a strategist should consider moving some assets into reserves. - */ - function accrueInterest(MarketParams memory market) public { - _validateMBMarket(market, identifier(), false); - _accrueInterest(market); - } - //============================== Interface Details ============================== // General message on interface and virtual functions below: The Morpho Blue protocol is meant to be a primitive layer to DeFi, and so other projects may build atop of MB. These possible future projects may implement the same interface to simply interact with MB, and thus this adaptor is implementing a design that allows for future adaptors to simply inherit this "Base Morpho Adaptor" and override what they need appropriately to work with whatever project. Aspects that may be adjusted include using the flexible `bytes` param within `morphoBlue.supplyCollateral()` for example. diff --git a/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueDebtAdaptor.sol b/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueDebtAdaptor.sol index fe9ed0f12..7144fe0c7 100644 --- a/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueDebtAdaptor.sol +++ b/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueDebtAdaptor.sol @@ -144,7 +144,7 @@ contract MorphoBlueDebtAdaptor is BaseAdaptor, MorphoBlueHelperLogic { function repayMorphoBlueDebt(MarketParams memory _market, uint256 _debtTokenRepayAmount) public { _validateMBMarket(_market, identifier(), true); Id id = MarketParamsLib.id(_market); - _accrueInterest(_market); + accrueInterest(_market); ERC20 tokenToRepay = ERC20(_market.loanToken); uint256 debtAmountToRepay = _maxAvailable(tokenToRepay, _debtTokenRepayAmount); tokenToRepay.safeApprove(address(morphoBlue), debtAmountToRepay); @@ -163,20 +163,6 @@ contract MorphoBlueDebtAdaptor is BaseAdaptor, MorphoBlueHelperLogic { _revokeExternalApproval(tokenToRepay, address(morphoBlue)); } - /** - * @notice Allows a strategist to call `accrueInterest()` on a MB Market cellar is using. - * @dev A strategist might want to do this if a MB market has not been interacted with - * in a while, and the strategist does not plan on interacting with it during a - * rebalance. - * @dev Calling this can increase the share price during the rebalance, - * so a strategist should consider moving some assets into reserves. - * @param _market identifier of a Morpho Blue market. - */ - function accrueInterest(MarketParams memory _market) public { - _validateMBMarket(_market, identifier(), true); - _accrueInterest(_market); - } - //============================== Interface Details ============================== // General message on interface and virtual functions below: The Morpho Blue protocol is meant to be a primitive layer to DeFi, and so other projects may build atop of MB. These possible future projects may implement the same interface to simply interact with MB, and thus this adaptor is implementing a design that allows for future adaptors to simply inherit this "Base Morpho Adaptor" and override what they need appropriately to work with whatever project. Aspects that may be adjusted include using the flexible `bytes` param within `morphoBlue.supplyCollateral()` for example. diff --git a/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueHelperLogic.sol b/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueHelperLogic.sol index da2a7c199..531067c4c 100644 --- a/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueHelperLogic.sol +++ b/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueHelperLogic.sol @@ -98,10 +98,15 @@ contract MorphoBlueHelperLogic { } /** - * @notice Caller calls `accrueInterest` on specified MB market. - * @param _market The specified MB market. + * @notice Allows a strategist to call `accrueInterest()` on a MB Market that the cellar is using. + * @dev A strategist might want to do this if a MB market has not been interacted with + * in a while, and the strategist does not plan on interacting with it during a + * rebalance. + * @dev Calling this can increase the share price during the rebalance, + * so a strategist should consider moving some assets into reserves. + * @param _market identifier of a Morpho Blue market. */ - function _accrueInterest(MarketParams memory _market) internal virtual { + function accrueInterest(MarketParams memory _market) public { morphoBlue.accrueInterest(_market); } diff --git a/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueSupplyAdaptor.sol b/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueSupplyAdaptor.sol index e08e8c081..7ba25caeb 100644 --- a/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueSupplyAdaptor.sol +++ b/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueSupplyAdaptor.sol @@ -196,20 +196,6 @@ contract MorphoBlueSupplyAdaptor is BaseAdaptor, MorphoBlueHelperLogic { } } - /** - * @notice Allows a strategist to call `accrueInterest()` on a MB Market that the cellar is using. - * @dev A strategist might want to do this if a MB market has not been interacted with - * in a while, and the strategist does not plan on interacting with it during a - * rebalance. - * @dev Calling this can increase the share price during the rebalance, - * so a strategist should consider moving some assets into reserves. - * @param _market identifier of a Morpho Blue market. - */ - function accrueInterest(MarketParams memory _market) public { - _validateMBMarket(_market, identifier(), false); - _accrueInterest(_market); - } - //============================================ Interface Helper Functions =========================================== //============================== Interface Details ============================== diff --git a/test/resources/AdaptorHelperFunctions.sol b/test/resources/AdaptorHelperFunctions.sol index 6720d8af9..d76e953d2 100644 --- a/test/resources/AdaptorHelperFunctions.sol +++ b/test/resources/AdaptorHelperFunctions.sol @@ -302,6 +302,12 @@ contract AdaptorHelperFunctions { // ========================================= Morpho Blue FUNCTIONS ========================================= + function _createBytesDataToAccrueInterestOnMorphoBlue( + MarketParams memory _market + ) internal pure returns (bytes memory) { + return abi.encodeWithSelector(MorphoBlueHelperLogic.accrueInterest.selector, _market); + } + // MorphoBlueSupplyAdaptor Functions function _createBytesDataToLendOnMorphoBlue( MarketParams memory _market, @@ -317,11 +323,11 @@ contract AdaptorHelperFunctions { return abi.encodeWithSelector(MorphoBlueSupplyAdaptor.withdrawFromMorphoBlue.selector, _market, _assets); } - function _createBytesDataToAccrueInterestToMorphoBlueSupplyAdaptor( - MarketParams memory _market - ) internal pure returns (bytes memory) { - return abi.encodeWithSelector(MorphoBlueSupplyAdaptor.accrueInterest.selector, _market); - } + // function _createBytesDataToAccrueInterestToMorphoBlueSupplyAdaptor( + // MarketParams memory _market + // ) internal pure returns (bytes memory) { + // return abi.encodeWithSelector(MorphoBlueSupplyAdaptor.accrueInterest.selector, _market); + // } // MorphoBlueCollateralAdaptor Functions @@ -341,11 +347,11 @@ contract AdaptorHelperFunctions { abi.encodeWithSelector(MorphoBlueCollateralAdaptor.removeCollateral.selector, _market, _collateralAmount); } - function _createBytesDataToAccrueInterestToMorphoBlue( - MarketParams memory _market - ) internal pure returns (bytes memory) { - return abi.encodeWithSelector(MorphoBlueCollateralAdaptor.accrueInterest.selector, _market); - } + // function _createBytesDataToAccrueInterestToMorphoBlue( + // MarketParams memory _market + // ) internal pure returns (bytes memory) { + // return abi.encodeWithSelector(MorphoBlueCollateralAdaptor.accrueInterest.selector, _market); + // } // MorphoBlueDebtAdaptor Functions diff --git a/test/testAdaptors/MorphoBlue/MorphoBlueSupplyAdaptor.t.sol b/test/testAdaptors/MorphoBlue/MorphoBlueSupplyAdaptor.t.sol index 5e76931fb..3d6840c0f 100644 --- a/test/testAdaptors/MorphoBlue/MorphoBlueSupplyAdaptor.t.sol +++ b/test/testAdaptors/MorphoBlue/MorphoBlueSupplyAdaptor.t.sol @@ -648,7 +648,7 @@ contract MorphoBlueSupplyAdaptorTest is MainnetStarterTest, AdaptorHelperFunctio Cellar.AdaptorCall[] memory data = new Cellar.AdaptorCall[](1); { bytes[] memory adaptorCalls = new bytes[](1); - adaptorCalls[0] = _createBytesDataToAccrueInterestToMorphoBlueSupplyAdaptor(usdcDaiMarket); + adaptorCalls[0] = _createBytesDataToAccrueInterestOnMorphoBlue(usdcDaiMarket); data[0] = Cellar.AdaptorCall({ adaptor: address(morphoBlueSupplyAdaptor), callData: adaptorCalls }); } @@ -676,7 +676,7 @@ contract MorphoBlueSupplyAdaptorTest is MainnetStarterTest, AdaptorHelperFunctio { bytes[] memory adaptorCalls = new bytes[](1); - adaptorCalls[0] = _createBytesDataToAccrueInterestToMorphoBlueSupplyAdaptor(usdcDaiMarket); + adaptorCalls[0] = _createBytesDataToAccrueInterestOnMorphoBlue(usdcDaiMarket); data[0] = Cellar.AdaptorCall({ adaptor: address(morphoBlueSupplyAdaptor), callData: adaptorCalls }); } cellar.callOnAdaptor(data);