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
| Parameter | Type | Default value | Description |
|---|---|---|---|
collateralAmount | bigint | undefined | The collateral amount in wei. |
creditedAmount | bigint | undefined | The credited amount in wei. |
scale | bigint | undefined | The 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. |
creditedPerUnitCollateral | bigint | undefined | The price. X, in the equation 1 Collateral = X Credited. |
priceExponent | number | 0 | The +/- 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.