Skip to content

Commit

Permalink
fix: issue-503
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisGD committed Dec 10, 2023
1 parent 8e7e4ce commit 95e3225
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/Morpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/interfaces/IMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 95e3225

Please sign in to comment.