Skip to content

Commit

Permalink
Resolve audit fix G-1 w/ accrueInterest()
Browse files Browse the repository at this point in the history
  • Loading branch information
0xEinCodes committed Jan 23, 2024
1 parent 2265d21 commit 343e155
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
16 changes: 1 addition & 15 deletions src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueDebtAdaptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.

Expand Down
11 changes: 8 additions & 3 deletions src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueHelperLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
14 changes: 0 additions & 14 deletions src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueSupplyAdaptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 ==============================
Expand Down
26 changes: 16 additions & 10 deletions test/resources/AdaptorHelperFunctions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand All @@ -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

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

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 343e155

Please sign in to comment.