diff --git a/src/LiquidationProtection.sol b/src/LiquidationProtection.sol index 36d03de..9a90764 100644 --- a/src/LiquidationProtection.sol +++ b/src/LiquidationProtection.sol @@ -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; @@ -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 @@ -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 { @@ -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); diff --git a/src/libraries/EventsLib.sol b/src/libraries/EventsLib.sol new file mode 100644 index 0000000..f40d1c6 --- /dev/null +++ b/src/libraries/EventsLib.sol @@ -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 security@morpho.org +/// @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); +}