Skip to content

API ReferenceReact provider and hooksFunction

useCollateralFactor()

function useCollateralFactor(params): UseCollateralFactorResult;

Fetches the current collateral factor for an ordered token pair.

Incomplete inputs remain idle without creating a query. A completed lookup for an unsupported pair returns null. Data fails closed after a refresh error or the freshness bound rather than retaining an unconfirmed value.

Parameters

ParameterTypeDescription
paramsUseCollateralFactorParamsThe ordered pair to read. Either token left undefined leaves the hook idle — no query, no cache entry.

Returns

UseCollateralFactorResult

The read envelope. data is the pair configuration, null for a completed read of an unsupported pair, and undefined while idle, before the first read settles, or once the value has failed closed. retry re-runs the latest completed or failed request.

Throws

Error when rendered outside <AnvilProvider>, by way of useAnvilSDK.

Example

export function PairSupport() {
const { data: factor, isLoading } = useCollateralFactor({
collateralToken: WETH,
creditedToken: USDC,
});
if (isLoading) return <p>Checking pair…</p>;
// `null` is a completed read for an unsupported pair. `undefined` is a
// value this hook refuses to stand behind: past its freshness bound, or
// after a failed refresh.
if (factor === null) return <p>Pair not supported.</p>;
if (factor === undefined) return <p>Pair configuration unavailable.</p>;
return <p>Liquidates at {factor.collateralFactorBasisPoints} bps.</p>;
}