Skip to content

Commit

Permalink
Resolve audit fixes L-2 & G-2
Browse files Browse the repository at this point in the history
  • Loading branch information
0xEinCodes committed Jan 24, 2024
1 parent 343e155 commit 731165d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
21 changes: 15 additions & 6 deletions src/modules/adaptors/Morpho/MorphoBlue/MorphoBlueSupplyAdaptor.sol
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 0 additions & 12 deletions test/resources/AdaptorHelperFunctions.sol
Expand Up @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 731165d

Please sign in to comment.