Skip to content

Commit

Permalink
add liquidate callback function
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasCImach committed Nov 1, 2024
1 parent f721053 commit d6cdd89
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions contracts/OverlayV1Market.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "./interfaces/IOverlayV1Factory.sol";
import "./interfaces/IOverlayV1Market.sol";
import "./interfaces/IOverlayV1Token.sol";
import "./interfaces/feeds/IOverlayV1Feed.sol";
import "./interfaces/callback/IOverlayMarketLiquidateCallback.sol";

import "./libraries/FixedCast.sol";
import "./libraries/FixedPoint.sol";
Expand Down Expand Up @@ -507,6 +508,11 @@ contract OverlayV1Market is IOverlayV1Market, Pausable {
pos.isLong ? oiLongShares : oiShortShares
);

// if the owner of the potision has LIQUIDATE_CALLBACK_ROLE, make a callback
if (ov.hasRole(LIQUIDATE_CALLBACK_ROLE, owner)) {
IOverlayMarketLiquidateCallback(owner).overlayMarketLiquidateCallback(positionId);
}

// burn the pnl for the position + insurance margin
ov.burn(cost - value + marginToBurn);

Expand Down
1 change: 1 addition & 0 deletions contracts/interfaces/IOverlayV1Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ bytes32 constant GOVERNOR_ROLE = keccak256("GOVERNOR");
bytes32 constant GUARDIAN_ROLE = keccak256("GUARDIAN");
bytes32 constant PAUSER_ROLE = keccak256("PAUSER");
bytes32 constant RISK_MANAGER_ROLE = keccak256("RISK_MANAGER");
bytes32 constant LIQUIDATE_CALLBACK_ROLE = keccak256("LIQUIDATE_CALLBACK");

interface IOverlayV1Token is IAccessControl, IERC20 {
// mint/burn
Expand Down
12 changes: 12 additions & 0 deletions contracts/interfaces/callback/IOverlayMarketLiquidateCallback.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;

/// @title Callback for OverlayV1Market#liquidate
interface IOverlayMarketLiquidateCallback {
/// @notice Called to `owner` after executing a liquidation.
/// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
/// @param positionId The positionId of the liquidated position
function overlayMarketLiquidateCallback(
uint256 positionId
) external;
}

0 comments on commit d6cdd89

Please sign in to comment.