PrimaryLendingPlatformLiquidationZksync

Overview

License: MIT

contract PrimaryLendingPlatformLiquidationZksync is PrimaryLendingPlatformLiquidationCore

The PrimaryLendingPlatformLiquidationZksync contract is the contract that allows users to liquidate positions for zksync network.

Contract that allows users to liquidate positions. Inherit from PrimaryLendingPlatformLiquidationCore.

Functions info

liquidate (0x39cb5c2a)

function liquidate(
    address _account,
    address _projectToken,
    address _lendingToken,
    uint256 _lendingTokenAmount,
    bytes32[] memory priceIds,
    bytes[] calldata updateData
)
    external
    payable
    isProjectTokenListed(_projectToken)
    isLendingTokenListed(_lendingToken)
    nonReentrant

Liquidates a user's position based on the specified lending token amount and update related token's prices.

The function to be called when a user wants to liquidate their position.

Requirements:

  • The project token is listed on the platform.

  • The lending token is listed on the platform.

  • The lending token amount must be greater than 0.

  • The user must have a position for the given project token and lending token.

  • The health factor must be less than 1.

  • _lendingTokenAmount must be within the permissible range of liquidation amount.

Effects:

  • Update price of related tokens.

  • Calculates the health factor of the position using getCurrentHealthFactor function.

  • Validates the health factor and ensures it's less than 1.

  • Calculates the permissible liquidation range using getLiquidationAmount function.

  • Validates lendingTokenAmount against the permissible range.

  • Determines the amount of project token to send to the liquidator.

  • Distributes rewards to the liquidator.

Parameters:

NameTypeDescription

_account

address

The address of the borrower

_projectToken

address

The address of the project token

_lendingToken

address

The address of the lending token

_lendingTokenAmount

uint256

The amount of lending tokens to be used for liquidation

priceIds

bytes32[]

An array of bytes32 price identifiers to update.

updateData

bytes[]

An array of bytes update data for the corresponding price identifiers.

liquidateFromModerator (0x6cc6d47e)

function liquidateFromModerator(
    address _account,
    address _projectToken,
    address _lendingToken,
    uint256 _lendingTokenAmount,
    address liquidator,
    bytes32[] memory priceIds,
    bytes[] calldata updateData
)
    external
    payable
    isProjectTokenListed(_projectToken)
    isLendingTokenListed(_lendingToken)
    onlyRelatedContracts
    nonReentrant
    returns (uint256)

Liquidates a portion of the borrower's debt using the lending token, called by a related contract and update related token's prices.

Requirements:

  • The project token is listed on the platform.

  • The lending token is listed on the platform.

  • Called by a related contract.

  • The lending token amount must be greater than 0.

  • The user must have a position for the given project token and lending token.

  • The health factor must be less than 1.

  • _lendingTokenAmount must be within the permissible range of liquidation amount.

Effects:

  • Update price of related tokens.

  • Calculates the health factor of the position using getCurrentHealthFactor function.

  • Validates the health factor and ensures it's less than 1.

  • Calculates the permissible liquidation range using getLiquidationAmount function.

  • Validates lendingTokenAmount against the permissible range.

  • Determines the amount of project token to send to the liquidator.

  • Distributes rewards to the liquidator.

Parameters:

NameTypeDescription

_account

address

The address of the borrower

_projectToken

address

The address of the project token

_lendingToken

address

The address of the lending token

_lendingTokenAmount

uint256

The amount of lending tokens to be used for liquidation

liquidator

address

The address of the liquidator

priceIds

bytes32[]

An array of bytes32 price identifiers to update.

updateData

bytes[]

An array of bytes update data for the corresponding price identifiers.

Return values:

NameTypeDescription

[0]

uint256

The amount of project tokens sent to the liquidator as a result of the liquidation.

getCurrentHealthFactorWithUpdatePrices (0xf9b5315f)

function getCurrentHealthFactorWithUpdatePrices(
    address _account,
    address _projectToken,
    address _lendingToken,
    bytes32[] memory priceIds,
    bytes[] calldata updateData
)
    external
    payable
    returns (uint256 healthFactorNumerator, uint256 healthFactorDenominator)

Gets the current health factor of a specific account's position after updating related token's prices.

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.

priceIds

bytes32[]

An array of bytes32 price identifiers to update.

updateData

bytes[]

An array of bytes update data for the corresponding price identifiers.

Return values:

NameTypeDescription

healthFactorNumerator

uint256

The numerator of the health factor.

healthFactorDenominator

uint256

The denominator of the health factor.

getTokenPriceWithUpdatePrices (0xd0ddd846)

function getTokenPriceWithUpdatePrices(
    address token,
    uint256 amount,
    bytes32[] memory priceIds,
    bytes[] calldata updateData
) external payable returns (uint256 price)

Gets the price of a token in USD after updating related token's prices.

Parameters:

NameTypeDescription

token

address

The address of the token.

amount

uint256

The amount of the token.

priceIds

bytes32[]

An array of bytes32 price identifiers to update.

updateData

bytes[]

An array of bytes update data for the corresponding price identifiers.

Return values:

NameTypeDescription

price

uint256

The price of the token in USD.

liquidatorRewardFactorWithUpdatePrices (0xe7f63838)

function liquidatorRewardFactorWithUpdatePrices(
    address _account,
    address _projectToken,
    address _lendingToken,
    bytes32[] memory priceIds,
    bytes[] calldata updateData
) external payable returns (uint256 lrfNumerator, uint256 lrfDenominator)

Calculates the liquidator reward factor (LRF) for a given position after after updating related token's prices. ####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.

priceIds

bytes32[]

An array of bytes32 price identifiers to update.

updateData

bytes[]

An array of bytes update data for the corresponding price identifiers.

Return values:

NameTypeDescription

lrfNumerator

uint256

The numerator of the liquidator reward factor.

lrfDenominator

uint256

The denominator of the liquidator reward factor.

getMaxLiquidationAmountWithUpdatePrices (0x25a695e5)

function getMaxLiquidationAmountWithUpdatePrices(
    address _account,
    address _projectToken,
    address _lendingToken,
    bytes32[] memory priceIds,
    bytes[] calldata updateData
) external payable returns (uint256 maxLA)

Calculates the maximum liquidation amount (MaxLA) for a given position after updating related token's prices. ####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.

priceIds

bytes32[]

An array of bytes32 price identifiers to update.

updateData

bytes[]

An array of bytes update data for the corresponding price identifiers.

Return values:

NameTypeDescription

maxLA

uint256

The maximum liquidator reward amount in the lending token.

getLiquidationAmountWithUpdatePrices (0x02dfa5d4)

function getLiquidationAmountWithUpdatePrices(
    address _account,
    address _projectToken,
    address _lendingToken,
    bytes32[] memory priceIds,
    bytes[] calldata updateData
) external payable returns (uint256 maxLA, uint256 minLA)

Returns the minimum and maximum liquidation amount for a given account, project token, and lending token after updating related token's prices.

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.

priceIds

bytes32[]

An array of bytes32 price identifiers to update.

updateData

bytes[]

An array of bytes update data for the corresponding price identifiers.

Return values:

NameTypeDescription

maxLA

uint256

The maximum liquidation amount.

minLA

uint256

The minimum liquidation amount.

Last updated