Skip to content

API ReferencePricing and oraclesFunction

computeLiquidationPrice()

function computeLiquidationPrice(
price,
collateralTokenAmount,
creditedTokenAmount,
liquidationCollateralFactorBasisPoints
): Price | undefined;

Computes the pair price at which a dynamic LOC’s position becomes liquidatable: the price at which the position’s current collateral factor (credited value ÷ collateral value) reaches the pair’s live liquidation threshold.

liquidationPrice = currentPrice × currentCollateralFactor ÷ liquidationCollateralFactor

As the collateral’s price falls, the position’s current collateral factor rises; the liquidation price is the price at which that ratio reaches the threshold.

Parameters

ParameterTypeDescription
pricePriceThe current pair price (collateral in terms of credited token, i.e. X in 1 collateral = X credited).
collateralTokenAmountbigintThe LOC’s collateral amount, in the collateral token’s smallest unit.
creditedTokenAmountbigintThe LOC’s credited amount, in the credited token’s smallest unit.
liquidationCollateralFactorBasisPointsbigint | undefinedThe asset pair’s current liquidation threshold (CollateralFactor.collateralFactorBasisPoints).

Returns

Price | undefined

The liquidation price, or undefined when the liquidation factor is 0 or undefined.

Remarks

A 0/undefined liquidation factor is an invariant violation, not a supported protocol state: LetterOfCredit.sol refuses to store a pair whose liquidation factor does not exceed its creation factor, and refuses to create a dynamic LOC on a pair with no creation factor, so a live dynamic LOC’s pair never carries a 0 liquidation factor. Reaching this function with 0/undefined means the caller’s upstream state is stale or unreadable — this returns indeterminate rather than a number, and never divides by the missing threshold.