PrimaryLendingPlatformLiquidationCore

Overview

License: MIT

abstract contract PrimaryLendingPlatformLiquidationCore is Initializable, AccessControlUpgradeable, ReentrancyGuardUpgradeable

Core contract for liquidating loans on the PrimaryLendingPlatform.

Abstract contract that allows users to liquidate loans.

Structs info

Ratio

struct Ratio {
	uint8 numerator;
	uint8 denominator;
}

MaxLAParams

struct MaxLAParams {
	uint256 numeratorMaxLA;
	uint256 denominatorMaxLA;
	uint256 calculatedMaxLA;
	uint256 maxLACompare;
}

Events info

Liquidate

event Liquidate(address indexed liquidator, address indexed borrower, address lendingToken, address indexed prjAddress, uint256 amountPrjLiquidated)

Emitted when a liquidation occurs.

Parameters:

SetPrimaryLendingPlatform

event SetPrimaryLendingPlatform(address indexed newPrimaryLendingPlatform)

Emitted when the primary lending platform address is set.

Parameters:

SetMinPartialLiquidationAmount

event SetMinPartialLiquidationAmount(uint256 indexed newAmount)

Emitted when the minimum amount for partial liquidation is set.

Parameters:

SetMaxLRF

event SetMaxLRF(uint8 numeratorLRF, uint8 denominatorLRF)

Emitted when the maximum Liquidation Reserve Factor (LRF) is set.

Parameters:

SetLiquidatorRewardCalculationFactor

event SetLiquidatorRewardCalculationFactor(uint8 numeratorLRF, uint8 denominatorLRF)

Emitted when the liquidator reward calculation factor is set.

Parameters:

SetTargetHealthFactor

event SetTargetHealthFactor(uint8 numeratorHF, uint8 denominatorHF)

Emitted when the target health factor is set.

Parameters:

Constants info

MODERATOR_ROLE (0x797669c9)

bytes32 constant MODERATOR_ROLE = keccak256("MODERATOR_ROLE")

LIQUIDATOR_REWARD_FACTOR_DECIMAL (0x150f2191)

uint256 constant LIQUIDATOR_REWARD_FACTOR_DECIMAL = 18

State variables info

minPartialLiquidationAmount (0x802937ac)

uint256 minPartialLiquidationAmount

targetHealthFactor (0x254cf439)

struct PrimaryLendingPlatformLiquidationCore.Ratio targetHealthFactor

liquidatorRewardCalcFactor (0xc9fd7f25)

struct PrimaryLendingPlatformLiquidationCore.Ratio liquidatorRewardCalcFactor

maxLRF (0x83958352)

struct PrimaryLendingPlatformLiquidationCore.Ratio maxLRF

primaryLendingPlatform (0x92641a7c)

contract IPrimaryLendingPlatform primaryLendingPlatform

Modifiers info

onlyAdmin

modifier onlyAdmin()

Modifier that only allows access to accounts with the DEFAULT_ADMIN_ROLE.

onlyModerator

modifier onlyModerator()

Modifier that only allows access to accounts with the MODERATOR_ROLE.

isProjectTokenListed

modifier isProjectTokenListed(address _projectToken)

Modifier that only allows access to project tokens that are listed on the PrimaryLendingPlatform.

Parameters:

isLendingTokenListed

modifier isLendingTokenListed(address _lendingToken)

Modifier that only allows access to lending tokens that are listed on the PrimaryLendingPlatform.

Parameters:

onlyRelatedContracts

modifier onlyRelatedContracts()

Modifier that only allows access to related contracts of the PrimaryLendingPlatform.

Functions info

initialize (0xc4d66de8)

function initialize(address pit) public initializer

Initializes the contract with the provided PIT address.

Sets up initial roles, initializes AccessControl, and sets the provided PIT address.

Parameters:

setMinPartialLiquidationAmount (0x35f67981)

function setMinPartialLiquidationAmount(
    uint256 newAmount
) external onlyModerator

Sets the minimum partial liquidation amount. Can only be called by accounts with the MODERATOR_ROLE.

Parameters:

setMaxLRF (0x1ed95f01)

function setMaxLRF(
    uint8 numeratorLRF,
    uint8 denominatorLRF
) external onlyModerator

Sets the maximum Liquidation Reserve Factor (LRF) that can be used for liquidation.

Requirements:

  • The denominator must not be zero.

  • Only the moderator can call this function.

Parameters:

setLiquidatorRewardCalculationFactor (0x3495b179)

function setLiquidatorRewardCalculationFactor(
    uint8 numeratorLRF,
    uint8 denominatorLRF
) external onlyModerator

Sets the liquidator reward calculation factor.

Requirements:

  • The caller must have the MODERATOR_ROLE role.

  • The denominatorLRF cannot be zero.

Parameters:

setPrimaryLendingPlatformAddress (0xcec5a0b0)

function setPrimaryLendingPlatformAddress(
    address newPrimaryLendingPlatform
) external onlyModerator

Sets the address of the primary lending platform contract.

Requirements:

  • Only the moderator can call this function.

  • The new primary lending platform address must not be the zero address.

Parameters:

setTargetHealthFactor (0xffac9b50)

function setTargetHealthFactor(
    uint8 numeratorHF,
    uint8 denominatorHF
) external onlyModerator

Sets the target health factor.

Requirements:

  • Only the moderator can call this function.

  • The denominatorHF cannot be zero.

Parameters:

getCurrentHealthFactor (0xb398f0e7)

function getCurrentHealthFactor(
    address _account,
    address _projectToken,
    address _lendingToken
)
    public
    view
    returns (uint256 healthFactorNumerator, uint256 healthFactorDenominator)

Gets the current health factor of a specific account's position.

Parameters:

Return values:

getTokenPrice (0xc9f7153c)

function getTokenPrice(
    address token,
    uint256 amount
) public view returns (uint256 price)

Gets the price of a token in USD.

Parameters:

Return values:

liquidatorRewardFactor (0x894c4d5b)

function liquidatorRewardFactor(
    address _account,
    address _projectToken,
    address _lendingToken
) public view returns (uint256 lrfNumerator, uint256 lrfDenominator)

Calculates the liquidator reward factor (LRF) for a given position.

Formula: LRF = (1 + (1 - HF) * k)

Parameters:

Return values:

getMaxLiquidationAmount (0x7da157b9)

function getMaxLiquidationAmount(
    address account,
    address projectToken,
    address lendingToken
) public view returns (uint256 maxLA)

Calculates the maximum liquidation amount (MaxLA) for a given position.

Formula: MaxLA = (LVR * CVc - THF * LVc) / (LRF * LVR - THF)

Parameters:

Return values:

getLiquidationAmount (0x90edd058)

function getLiquidationAmount(
    address _account,
    address _projectToken,
    address _lendingToken
) public view returns (uint256 maxLA, uint256 minLA)

Returns the minimum and maximum liquidation amount for a given account, project token, and lending token.

Formula:

  • MinLA = min(MaxLA, MPA)

  • MaxLA = (LVR * CVc - THF * LVc) / (LRF * LVR - THF)

Parameters:

Return values:

Last updated