From 731165df55092a655ff892dfb221f0a34ef660c2 Mon Sep 17 00:00:00 2001 From: 0xEinCodes <0xEinCodes@gmail.com> Date: Tue, 23 Jan 2024 17:10:32 -0600 Subject: [PATCH] Resolve audit fixes L-2 & G-2 --- .../MorphoBlue/MorphoBlueSupplyAdaptor.sol | 21 +++++++++++++------ test/resources/AdaptorHelperFunctions.sol | 12 ----------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueSupplyAdaptor.sol b/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueSupplyAdaptor.sol index 7ba25caeb..8fe8d13f3 100644 --- a/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueSupplyAdaptor.sol +++ b/src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueSupplyAdaptor.sol @@ -2,11 +2,11 @@ pragma solidity 0.8.21; import { BaseAdaptor, ERC20, SafeTransferLib, Cellar, PriceRouter, Math } from "src/modules/adaptors/BaseAdaptor.sol"; -import { IMorpho, MarketParams, Id } from "src/interfaces/external/Morpho/MorphoBlue/interfaces/IMorpho.sol"; -import { MorphoBalancesLib } from "src/interfaces/external/Morpho/MorphoBlue/libraries/periphery/MorphoBalancesLib.sol"; +import { IMorpho, MarketParams, Id, Market } from "src/interfaces/external/Morpho/MorphoBlue/interfaces/IMorpho.sol"; import { MorphoLib } from "src/interfaces/external/Morpho/MorphoBlue/libraries/periphery/MorphoLib.sol"; import { MorphoBlueHelperLogic } from "src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueHelperLogic.sol"; import { MarketParamsLib } from "src/interfaces/external/Morpho/MorphoBlue/libraries/MarketParamsLib.sol"; +import { SharesMathLib } from "src/interfaces/external/Morpho/MorphoBlue/libraries/SharesMathLib.sol"; /** * @title Morpho Blue Supply Adaptor @@ -23,8 +23,8 @@ contract MorphoBlueSupplyAdaptor is BaseAdaptor, MorphoBlueHelperLogic { using SafeTransferLib for ERC20; using Math for uint256; using MorphoLib for IMorpho; - using MorphoBalancesLib for IMorpho; using MarketParamsLib for MarketParams; + using SharesMathLib for uint256; //==================== Adaptor Data Specification ==================== // adaptorData = abi.encode(MarketParams market) @@ -124,11 +124,20 @@ contract MorphoBlueSupplyAdaptor is BaseAdaptor, MorphoBlueHelperLogic { bool isLiquid = abi.decode(configurationData, (bool)); if (isLiquid) { - MarketParams memory market = abi.decode(adaptorData, (MarketParams)); - (uint256 totalSupplyAssets, , uint256 totalBorrowAssets, ) = morphoBlue.expectedMarketBalances(market); + MarketParams memory marketParams = abi.decode(adaptorData, (MarketParams)); + Id id = MarketParamsLib.id(marketParams); + Market memory market = morphoBlue.market(id); + uint256 totalBorrowAssets = market.totalBorrowAssets; + uint256 totalSupplyAssets = market.totalSupplyAssets; + uint256 totalSupplyShares = market.totalSupplyShares; + if (totalBorrowAssets >= totalSupplyAssets) return 0; uint256 liquidSupply = totalSupplyAssets - totalBorrowAssets; - uint256 cellarSuppliedBalance = morphoBlue.expectedSupplyAssets(market, msg.sender); + + uint256 cellarSuppliedBalance = ( + morphoBlue.supplyShares(id, msg.sender).toAssetsDown(totalSupplyAssets, totalSupplyShares) + ); + withdrawableSupply = cellarSuppliedBalance > liquidSupply ? liquidSupply : cellarSuppliedBalance; } else return 0; } diff --git a/test/resources/AdaptorHelperFunctions.sol b/test/resources/AdaptorHelperFunctions.sol index d76e953d2..1c8ace824 100644 --- a/test/resources/AdaptorHelperFunctions.sol +++ b/test/resources/AdaptorHelperFunctions.sol @@ -323,12 +323,6 @@ 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); - // } - // MorphoBlueCollateralAdaptor Functions function _createBytesDataToAddCollateralToMorphoBlue( @@ -347,12 +341,6 @@ 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); - // } - // MorphoBlueDebtAdaptor Functions function _createBytesDataToBorrowFromMorphoBlue(