Skip to content

API ReferenceReact provider and hooksFunction

useRequiredCollateral()

function useRequiredCollateral(
creditedAmount?,
collateralToken?,
creditedToken?,
oraclePrice?
): UseRequiredCollateralResult;

Fetches the minimum collateral a dynamic LOC must lock to clear the pair’s creation collateral factor.

The hook stays idle — no query, no cache entry — until every argument is present and creditedAmount is positive. With a supplied oraclePrice the result is held fresh for 30 seconds and not polled, because the caller owns that price’s refresh; without one the hook also re-reads every 30 seconds so its internal price does not go stale.

Parameters

ParameterTypeDescription
creditedAmount?bigintAmount the LOC will credit the beneficiary, in the credited token’s smallest unit. 0n or less leaves the hook idle.
collateralToken?`0x${string}`ERC-20 the LOC is collateralized in.
creditedToken?`0x${string}`ERC-20 the LOC credits to the beneficiary.
oraclePrice?PricePair price to reuse (for example from useTokenPairPrice), which skips the redundant internal getPrice read. Omit to let the query fetch its own.

Returns

UseRequiredCollateralResult

The read envelope. data is the required collateral in the collateral token’s smallest unit, null for a completed read of an unsupported pair, and undefined while idle or before the first read settles.

Throws

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

Example

export function MinimumCollateral({ credited }: { credited: bigint }) {
// Idle until every argument is present and `credited` is positive.
const { data: required } = useRequiredCollateral(credited, WETH, USDC);
return <span>{required?.toString() ?? '—'}</span>;
}