Skip to content

API ReferenceVaults, collateral, and riskFunction

calculateRiskFactorBasisPoints()

function calculateRiskFactorBasisPoints(
collateralAmount,
creditedAmount,
collateralFactorBasisPoints,
creditedPerUnitCollateral,
priceExponent?,
maxOneHundredPercent?
): number;

Calculates the risk factor in basis points, given the collateral and credited assets, the price, and the Liquidation Collateral Factor.

Risk Factor = Current Collateral Factor / Liquidation Collateral Factor, represented in basis points.

Parameters

ParameterTypeDefault valueDescription
collateralAmountbigintundefinedThe collateral amount in wei.
creditedAmountbigintundefinedThe credited amount in wei.
collateralFactorBasisPointsnumberundefinedThe liquidation collateral factor. A value of 0 (e.g. a disabled or unconfigured asset pair — see checkCreditedTokenValidity) is a divide-by-zero input, not “no risk”: with maxOneHundredPercent: false it returns UINT16_MAX_BASIS_POINTS (see isInsufficientSentinel), the same sentinel calculateCollateralFactorBasisPoints uses for its zero-value case; the default capped path returns 10_000 instead, so the position reads as maximally risky rather than risk-free either way.
creditedPerUnitCollateralbigintundefinedThe price. X, in the equation 1 Collateral = X Credited.
priceExponentnumber0The +/- exponent of the price if it cannot easily be represented without losing precision.
maxOneHundredPercentbooleantrueWhether the returned amount should be capped at 10000 basis points.

Returns

number

The risk factor in basis points. Risk factors above 10000 are possible but will be listed as 10000 if maxOneHundredPercent is true. A zero liquidation factor uses that cap for display results and preserves the contract’s uint16 sentinel for uncapped results.