From 95e3225ae516f89d1bd0bbac94605829f2b18cd9 Mon Sep 17 00:00:00 2001 From: MathisGD Date: Sun, 10 Dec 2023 16:34:46 +0100 Subject: [PATCH] fix: issue-503 --- src/Morpho.sol | 8 ++++---- src/interfaces/IMorpho.sol | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Morpho.sol b/src/Morpho.sol index 688113b2d..9d1b805b9 100644 --- a/src/Morpho.sol +++ b/src/Morpho.sol @@ -400,11 +400,11 @@ contract Morpho is IMorphoStaticTyping { position[id][borrower].borrowShares = 0; } - IERC20(marketParams.collateralToken).safeTransfer(msg.sender, seizedAssets); - // `repaidAssets` may be greater than `totalBorrowAssets` by 1. emit EventsLib.Liquidate(id, msg.sender, borrower, repaidAssets, repaidShares, seizedAssets, badDebtShares); + IERC20(marketParams.collateralToken).safeTransfer(msg.sender, seizedAssets); + if (data.length > 0) IMorphoLiquidateCallback(msg.sender).onMorphoLiquidate(repaidAssets, data); IERC20(marketParams.loanToken).safeTransferFrom(msg.sender, address(this), repaidAssets); @@ -416,10 +416,10 @@ contract Morpho is IMorphoStaticTyping { /// @inheritdoc IMorphoBase function flashLoan(address token, uint256 assets, bytes calldata data) external { - IERC20(token).safeTransfer(msg.sender, assets); - emit EventsLib.FlashLoan(msg.sender, token, assets); + IERC20(token).safeTransfer(msg.sender, assets); + IMorphoFlashLoanCallback(msg.sender).onMorphoFlashLoan(assets, data); IERC20(token).safeTransferFrom(msg.sender, address(this), assets); diff --git a/src/interfaces/IMorpho.sol b/src/interfaces/IMorpho.sol index 502bdd31b..fb53f510c 100644 --- a/src/interfaces/IMorpho.sol +++ b/src/interfaces/IMorpho.sol @@ -129,7 +129,8 @@ interface IMorphoBase { /// @notice Supplies `assets` or `shares` on behalf of `onBehalf`, optionally calling back the caller's /// `onMorphoSupply` function with the given `data`. - /// @dev Either `assets` or `shares` should be zero. Most usecases should rely on `assets` as an input so the caller + /// @dev Either `assets` or `shares` should be zero. Most use cases should rely on `assets` as an input so the + /// caller /// is guaranteed to have `assets` tokens pulled from their balance, but the possibility to mint a specific amount /// of shares is given for full compatibility and precision. /// @dev Supplying a large amount can revert for overflow. @@ -172,7 +173,8 @@ interface IMorphoBase { ) external returns (uint256 assetsWithdrawn, uint256 sharesWithdrawn); /// @notice Borrows `assets` or `shares` on behalf of `onBehalf` to `receiver`. - /// @dev Either `assets` or `shares` should be zero. Most usecases should rely on `assets` as an input so the caller + /// @dev Either `assets` or `shares` should be zero. Most use cases should rely on `assets` as an input so the + /// caller /// is guaranteed to borrow `assets` of tokens, but the possibility to mint a specific amount of shares is given for /// full compatibility and precision. /// @dev `msg.sender` must be authorized to manage `onBehalf`'s positions.