Skip to content

API ReferenceVaults, collateral, and riskFunction

calculateCollateralFactorWithScale()

function calculateCollateralFactorWithScale(
collateralAmount,
creditedAmount,
scale,
creditedPerUnitCollateral,
priceExponent?
): bigint;

Calculates the collateral factor, given the collateral and credited assets and the price, scaled according to the scale parameter.

NOT a contract mirror: the ratio keeps the price as a rational until the final division, preserving positive sub-wei collateral value for display math at arbitrary scales (e.g. liquidation-price derivation at scale 1e30). Anything that must agree with the chain’s accept/reject decisions uses calculateCollateralFactorBasisPoints instead.

Parameters

ParameterTypeDefault valueDescription
collateralAmountbigintundefinedThe collateral amount in wei.
creditedAmountbigintundefinedThe credited amount in wei.
scalebigintundefinedThe value to scale the collateral factor by in order to maintain precision. For instance, 100 would be the scale if you want a %, 10_000 would be the scale for basis points, etc.
creditedPerUnitCollateralbigintundefinedThe price. X, in the equation 1 Collateral = X Credited.
priceExponentnumber0The +/- exponent of the price if it cannot easily be represented without losing precision.

Returns

bigint

The scaled credited-to-collateral value ratio, rounded toward zero only at the final division. It can exceed scale for undercollateralized positions. Zero collateral or a zero price returns 0n.