Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: PoL integration #207

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 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 @@ -150,6 +151,8 @@ contract OverlayV1Market is IOverlayV1Market, Pausable {
/// @param oiShort oiShort after public update
event Update(uint256 oiLong, uint256 oiShort);

event LiquidateCallbackFailed(address owner, uint256 positionId);

constructor() {
(address _ovl, address _feed, address _factory) =
IOverlayV1Deployer(msg.sender).parameters();
Expand Down Expand Up @@ -432,6 +435,17 @@ contract OverlayV1Market is IOverlayV1Market, Pausable {
uint256 marginToBurn;
uint256 marginRemaining;
Position.Info memory pos;

// if the owner of the potision has LIQUIDATE_CALLBACK_ROLE, make a callback
// must be executed before the new postion state is stored
// attempt the callback without reverting on failure
if (ovl.hasRole(LIQUIDATE_CALLBACK_ROLE, owner)) {
try IOverlayMarketLiquidateCallback(owner).overlayMarketLiquidateCallback(positionId) {}
catch {
emit LiquidateCallbackFailed(owner, positionId);
}
}

// avoids stack too deep
{
// check position exists
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
10 changes: 10 additions & 0 deletions contracts/interfaces/callback/IOverlayMarketLiquidateCallback.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 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;
}
Loading