Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/licence' into refactor/subs…
Browse files Browse the repository at this point in the history
…cription-id
  • Loading branch information
QGarchery committed Sep 3, 2024
2 parents 6982647 + 21187cc commit 27b497e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/LiquidationProtection.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {MathLib} from "../lib/morpho-blue/src/libraries/MathLib.sol";
import {SharesMathLib} from "../lib/morpho-blue/src/libraries/SharesMathLib.sol";
import {SafeTransferLib} from "../lib/solmate/src/utils/SafeTransferLib.sol";
import {ERC20} from "../lib/solmate/src/tokens/ERC20.sol";
import {EventsLib} from "./libraries/EventsLib.sol";

struct SubscriptionParams {
uint256 slltv;
Expand Down Expand Up @@ -51,12 +52,22 @@ contract LiquidationProtection {
// should there be a max liquidation incentive ?

subscriptions[subscriptionId] = subscriptionParams;

emit EventsLib.Subscribe(
msg.sender,
marketId,
subscriptionParams.slltv,
subscriptionParams.closeFactor,
subscriptionParams.liquidationIncentive
);
}

function unsubscribe(Id marketId) public {
bytes32 subscriptionId = computeSubscriptionId(msg.sender, marketId);

subscriptions[subscriptionId].isValid = false;

emit EventsLib.Unsubscribe(msg.sender, marketId);
}

// @dev this function does not _accrueInterest() on Morpho when computing health
Expand Down Expand Up @@ -105,7 +116,9 @@ contract LiquidationProtection {
bytes memory callbackData = abi.encode(marketParams, seizedAssets, repaidAssets, borrower, msg.sender, data);
MORPHO.repay(marketParams, 0, repaidShares, borrower, callbackData);

subscriptions[subscriptionId].isValid = false;
emit EventsLib.Liquidate(
marketParams.id(), msg.sender, borrower, repaidAssets, repaidShares, seizedAssets, 0, 0
);
}

function onMorphoRepay(uint256 assets, bytes calldata callbackData) external {
Expand All @@ -120,7 +133,7 @@ contract LiquidationProtection {

MORPHO.withdrawCollateral(marketParams, seizedAssets, borrower, liquidator);

if (data.length > 0) IMorphoLiquidateCallback(msg.sender).onMorphoLiquidate(assets, data);
if (data.length > 0) IMorphoLiquidateCallback(liquidator).onMorphoLiquidate(assets, data);

ERC20(marketParams.loanToken).safeTransferFrom(liquidator, address(this), repaidAssets);

Expand Down
27 changes: 27 additions & 0 deletions src/libraries/EventsLib.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {Id, MarketParams} from "../../lib/morpho-blue/src/interfaces/IMorpho.sol";

/// @title EventsLib
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Library exposing events.
library EventsLib {
event Liquidate(
Id indexed id,
address indexed caller,
address indexed borrower,
uint256 repaidAssets,
uint256 repaidShares,
uint256 seizedAssets,
uint256 badDebtAssets,
uint256 badDebtShares
);

event Subscribe(
address indexed borrower, Id indexed marketId, uint256 slltv, uint256 closeFactor, uint256 liquidationIncentive
);

event Unsubscribe(address indexed borrower, Id indexed marketId);
}

0 comments on commit 27b497e

Please sign in to comment.