Skip to Content
docs

Aave V3 Health Factor Preview

Preview how a supply, borrow, repay or withdraw changes a user’s health factor before sending it.

The health factor compares the liquidation-weighted collateral to the debt:

Health Factor=Total Collateral Value×Weighted Average Collateral FactorTotal Borrow Value\text{Health Factor} = \frac{\text{Total Collateral Value} \times \text{Weighted Average Collateral Factor}}{\text{Total Borrow Value}}

A health factor below 1 makes the position eligible for liquidation.

Liquidatable0<1Safe≥12+Borrow and WithdrawLowers Health FactorSupply and RepayRaises Health Factor
Health Factor

The health factor is null unless the user has at least one active borrow.

To preview how a user’s health factor will change before executing a market operation (supply, borrow, repay, withdraw), use the useAaveHealthFactorPreview hook in React, the healthFactorPreview client action in TypeScript, or the healthFactorPreview query in GraphQL.

import { useWalletClient } from "wagmi";
import { useAaveHealthFactorPreview, bigDecimal, evmAddress } from "@aave/react";

// …

const { data: walletClient } = useWalletClient();
const [preview, { loading, error }] = useAaveHealthFactorPreview();

const execute = async () => {
  const result = await preview({
    action: {
      borrow: {
        market: reserve.market.address,
        amount: {
          erc20: {
            currency: reserve.underlyingToken.address,
            value: bigDecimal(42), // 42 WETH
          },
        },
        sender: evmAddress(walletClient!.account.address),
        chainId: reserve.market.chain.chainId,
      },
    },
  });

  if (result.isErr()) {
    console.error(result.error);
  } else {
    console.log(result.value.after); // 1.5 or null
  }
};