API ReferenceReact provider and hooksFunction
useLiquidationDetails()
function useLiquidationDetails(params): UseLiquidationDetailsResult;Computes liquidation-facing values used by dynamic LOC UIs.
Two different thresholds are in play and are deliberately not conflated: requiredCollateral clears
the pair’s creation minimum, the lower bar a new LOC must meet, while liquidationPrice and the
risk fields are measured against the liquidation threshold. Both derived values are undefined
until the amounts are positive and the pair configuration and price have both been read.
Parameters
| Parameter | Type | Description |
|---|---|---|
params | UseLiquidationDetailsParams | The dynamic LOC’s amounts and token pair. Every field is optional so the hook can be mounted before a form is complete; leave either token unset to fetch nothing. |
Returns
The liquidation view of the position: status (from useRiskFactor) says whether
the numbers mean anything, requiredCollateral is the creation minimum, liquidationPrice is the
pair price at which the position becomes liquidatable, and riskFactorBasisPoints, riskLevel,
collateralFactor, pairPrice, isLoading, and error pass through unchanged.
Throws
Error when rendered outside <AnvilProvider>, by way of useAnvilSDK.
Example
export function LOCPreview() { const [credited, setCredited] = useState(1_000_000_000n); const details = useLiquidationDetails({ collateralAmount: 1_000_000_000_000_000_000n, creditedAmount: credited, collateralToken: WETH, creditedToken: USDC, });
return ( <> <button onClick={() => setCredited(credited * 2n)}>×2</button> {/* requiredCollateral clears the CREATION minimum; liquidationPrice is measured against the liquidation threshold. */} <p>Needs {details.requiredCollateral?.toString() ?? '—'}</p> <p>Liquidates at {details.liquidationPrice?.price.toString()}</p> </> );}