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:

NameTypeDescription

liquidator

address

The address of the account that initiates the liquidation.

borrower

address

The address of the borrower whose position is being liquidated.

lendingToken

address

The address of the token being used for lending.

prjAddress

address

The address of the project being liquidated.

amountPrjLiquidated

uint256

The amount of the project's tokens being liquidated.

SetPrimaryLendingPlatform

event SetPrimaryLendingPlatform(address indexed newPrimaryLendingPlatform)

Emitted when the primary lending platform address is set.

Parameters:

NameTypeDescription

newPrimaryLendingPlatform

address

The new primary lending platform address.

SetMinPartialLiquidationAmount

event SetMinPartialLiquidationAmount(uint256 indexed newAmount)

Emitted when the minimum amount for partial liquidation is set.

Parameters:

NameTypeDescription

newAmount

uint256

The new minimum amount for partial liquidation.

SetMaxLRF

event SetMaxLRF(uint8 indexed numeratorLRF, uint8 indexed denominatorLRF)

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

Parameters:

NameTypeDescription

numeratorLRF

uint8

The numerator of the LRF fraction.

denominatorLRF

uint8

The denominator of the LRF fraction.

SetLiquidatorRewardCalculationFactor

event SetLiquidatorRewardCalculationFactor(uint8 indexed numeratorLRF, uint8 indexed denominatorLRF)

Emitted when the liquidator reward calculation factor is set.

Parameters:

NameTypeDescription

numeratorLRF

uint8

The numerator of the liquidator reward calculation factor.

denominatorLRF

uint8

The denominator of the liquidator reward calculation factor.

SetTargetHealthFactor

event SetTargetHealthFactor(uint8 numeratorHF, uint8 denominatorHF)

Emitted when the target health factor is set.

Parameters:

NameTypeDescription

numeratorHF

uint8

The numerator of the target health factor.

denominatorHF

uint8

The denominator of the target health factor.

SetExchangeAggregator

event SetExchangeAggregator(address indexed exchangeAggregator, address indexed registryAggregator)

Emitted when the exchange aggregator and registry aggregator addresses are set.

Parameters:

NameTypeDescription

exchangeAggregator

address

The address of the exchange aggregator.

registryAggregator

address

The address of the registry aggregator.

Constants info

MODERATOR_ROLE (0x797669c9)

bytes32 constant MODERATOR_ROLE = keccak256("MODERATOR_ROLE")

LIQUIDATOR_REWARD_FACTOR_DECIMAL (0x150f2191)

uint256 constant LIQUIDATOR_REWARD_FACTOR_DECIMAL = 18

BUFFER_PERCENTAGE (0x952038c2)

uint16 constant BUFFER_PERCENTAGE = 500

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

exchangeAggregator (0x60df4f35)

address exchangeAggregator

registryAggregator (0xf38cb29a)

address registryAggregator

Modifiers info

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:

NameTypeDescription

_projectToken

address

The address of the project token.

isLendingTokenListed

modifier isLendingTokenListed(address _lendingToken)

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

Parameters:

NameTypeDescription

_lendingToken

address

The address of the lending token.

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:

NameTypeDescription

pit

address

The address of the PrimaryLendingPlatform contract.

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:

NameTypeDescription

newAmount

uint256

The minimum partial liquidation amount.

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:

NameTypeDescription

numeratorLRF

uint8

The numerator of the LRF ratio.

denominatorLRF

uint8

The denominator of the LRF ratio.

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:

NameTypeDescription

numeratorLRF

uint8

The numerator of the liquidator reward calculation factor.

denominatorLRF

uint8

The denominator of the liquidator reward calculation factor.

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:

NameTypeDescription

newPrimaryLendingPlatform

address

The address of the new primary lending platform contract.

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:

NameTypeDescription

numeratorHF

uint8

The numerator for the target health factor.

denominatorHF

uint8

The denominator for the target health factor.

setExchangeAggregator (0x3c4841b4)

function setExchangeAggregator(
    address exchangeAggregatorAddress,
    address registryAggregatorAddress
) external onlyModerator

Updates the Exchange Aggregator contract and registry contract addresses.

Requirements:

  • The caller must be the moderator.

  • exchangeAggregatorAddress must not be the zero address.

  • registryAggregatorAddress must be a valid Augustus contract if it is not the zero address.

Parameters:

NameTypeDescription

exchangeAggregatorAddress

address

The new address of the Exchange Aggregator contract.

registryAggregatorAddress

address

The new address of the Aggregator registry contract.

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:

NameTypeDescription

_account

address

The address of the account.

_projectToken

address

The address of the project token.

_lendingToken

address

The address of the lending token.

Return values:

NameTypeDescription

healthFactorNumerator

uint256

The numerator of the health factor.

healthFactorDenominator

uint256

The denominator of the health factor.

getCurrentOutstanding (0x9bfeb5d5)

function getCurrentOutstanding(
    address _account,
    address _projectToken,
    address _lendingToken
) public view returns (uint256)

Gets the current outstanding amount of a specific account's position.

Parameters:

NameTypeDescription

_account

address

The address of the account.

_projectToken

address

The address of the project token.

_lendingToken

address

The address of the lending token.

Return values:

NameTypeDescription

[0]

uint256

currentOutstanding The current outstanding amount of the account's position.

getTokenPrice (0xc9f7153c)

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

Gets the price of a token in USD.

Parameters:

NameTypeDescription

token

address

The address of the token.

amount

uint256

The amount of the token.

Return values:

NameTypeDescription

collateralPrice

uint256

The price of the token in USD.

capitalPrice

uint256

The price of the token in USD.

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:

NameTypeDescription

_account

address

The address of the borrower whose position is being considered.

_projectToken

address

The address of the project token.

_lendingToken

address

The address of the lending token.

Return values:

NameTypeDescription

lrfNumerator

uint256

The numerator of the liquidator reward factor.

lrfDenominator

uint256

The denominator of the liquidator reward factor.

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:

NameTypeDescription

account

address

The address of the borrower whose position is being considered.

projectToken

address

The address of the project token.

lendingToken

address

The address of the lending token.

Return values:

NameTypeDescription

maxLA

uint256

The maximum liquidation amount in the lending token.

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:

NameTypeDescription

_account

address

The account for which to calculate the liquidation amount.

_projectToken

address

The project token address.

_lendingToken

address

The lending token address.

Return values:

NameTypeDescription

maxLA

uint256

The maximum liquidation amount.

minLA

uint256

The minimum liquidation amount.

Last updated