Skip to main content

MarketLiquidateFacet.sol

MarketLiquidateFacet

A contract that manages liquidations.

claimPosition

function claimPosition(uint256 positionId, address keeper, uint256 keeperFee) external

This function can only be called by the chromatic liquidator contract. Throws a NotExistPosition error if the requested position does not exist. Throws a NotClaimablePosition error if the position's close version is not in the past, indicating that it is not claimable.

  • Parameters:

    NameTypeDescription
    positionIduint256The ID of the position to claim.
    keeperaddressThe address of the keeper claiming the position.
    keeperFeeuint256The native token amount of the keeper's fee.

liquidate

function liquidate(uint256 positionId, address keeper, uint256 keeperFee) external

This function can only be called by the chromatic liquidator contract. The liquidation process checks if the position should be liquidated based on its profitability. If the position does not meet the liquidation criteria, the function returns without performing any action. Throws a NotExistPosition error if the requested position does not exist. Throws an AlreadyClosedPosition error if the position is already closed.

  • Parameters:

    NameTypeDescription
    positionIduint256The ID of the position to liquidate.
    keeperaddressThe address of the keeper performing the liquidation.
    keeperFeeuint256The native token amount of the keeper's fee.

checkLiquidation

function checkLiquidation(uint256 positionId) external view returns (bool _liquidate)

Checks if a position is eligible for liquidation.

  • Parameters:

    NameTypeDescription
    positionIduint256The ID of the position to check.
  • Return Values:

    NameTypeDescription
    _liquidateboolA boolean indicating if the position is eligible for liquidation.

checkLiquidationWithOracleVersion

function checkLiquidationWithOracleVersion(uint256 positionId, struct IOracleProvider.OracleVersion oracleVersion) external view returns (bool _liquidate)

Checks if a position is eligible for liquidation.

  • Parameters:

    NameTypeDescription
    positionIduint256The ID of the position to check.
    oracleVersionstruct IOracleProvider.OracleVersionThe oracle version data for liquidation check.
  • Return Values:

    NameTypeDescription
    _liquidateboolA boolean indicating if the position is eligible for liquidation.

_checkLiquidation

function _checkLiquidation(struct LpContext ctx, struct Position position, struct IOracleProvider.OracleVersion oracleVersion) internal view returns (bool _liquidate, int256 _pnl)

Internal function for checking if a position should be liquidated.

  • Parameters:

    NameTypeDescription
    ctxstruct LpContextThe LpContext containing the current oracle version and synchronization information.
    positionstruct PositionThe Position object representing the position to be checked.
    oracleVersionstruct IOracleProvider.OracleVersionThe oracle version data for liquidation check.
  • Return Values:

    NameTypeDescription
    _liquidateboolA boolean indicating whether the position should be liquidated.
    _pnlint256The profit or loss amount of the position.

checkClaimPosition

function checkClaimPosition(uint256 positionId) external view returns (bool)

Checks if a position is eligible for claim.

  • Parameters:

    NameTypeDescription
    positionIduint256The ID of the position to check.
  • Return Values:

    NameTypeDescription
    [0]boolA boolean indicating if the position is eligible for claim.