API ReferenceReact provider and hooksFunction
useRiskFactor()
function useRiskFactor(params): UseRiskFactorResult;Computes risk factor data for the provided dynamic LOC values. The pair’s current configuration governs open LOCs and creation previews alike — there is no per-LOC threshold to anchor to, so changing a pair’s configuration changes an already-open LOC’s risk.
Fails closed: see RiskFactorStatus and useCollateralFactor.
Parameters
| Parameter | Type | Description |
|---|---|---|
params | UseRiskFactorParams | The dynamic LOC’s amounts, token pair, and which configured factor to score against. Every field is optional so the hook can be mounted before a form is complete; incomplete inputs report incomplete and fetch nothing. |
Returns
The score and the inputs it was derived from. Read status first: only ready means
riskFactorBasisPoints and riskLevel hold values. collateralFactor and pairPrice are exposed
so a caller can show the same numbers without re-reading them, and error carries the first failure
from either leg.
Throws
Error when rendered outside <AnvilProvider>, by way of useAnvilSDK.
Example
export function RiskBadge({ collateral }: { collateral: bigint }) { const risk = useRiskFactor({ collateralAmount: collateral, creditedAmount: 1_000_000_000n, collateralToken: WETH, creditedToken: USDC, });
// Four distinct facts, deliberately not collapsed: `incomplete` waits on // the form, `loading` on the first read, `unavailable` on a pair // configuration or price the hook will not guess at. switch (risk.status) { case 'incomplete': return <span>Enter amounts</span>; case 'loading': return <span>Calculating…</span>; case 'unavailable': return <span>Risk unavailable</span>; case 'ready': return <span>{risk.riskLevel}</span>; }}