Matador Docs
DeFi Automation

Recipe - Aave Health Factor Guard

A policy to prevent liquidation by monitoring Health Factor.

Recipe: Aave Health Factor Guard

This policy allows a Keeper to manage debt on Aave (repay or supply collateral), but enforces that the Health Factor (HF) must improve or stay above a safety threshold.

The Strategy

Trigger: HF drops below 1.1 (Risk of liquidation).

Action: Supply more collateral OR repay debt.

Safety: The transaction MUST result in HF > 1.15.

Health-factor reads prevent stale assumptions

The policy reads Aave V3 health factor from the Pool ABI when the policy is evaluated, rather than trusting keeper-provided math.

The Policy

import "abis/AavePool.json" as AavePool;

permission AaveHealthGuard -> 1.0.0 {
    parameters: {
        authorizer: address,
        pool: AavePool,
        account: address,
        minHealthFactor: uint256
    }

    pub fn authorize() -> bool {
        return authorizedBy(parameters.authorizer);
    }

    fn main() -> bool {
        if (context.target != parameters.pool) {
            return false;
        }

        if (context.selector == AavePool.supply) {
            if (AavePool.supply.onBehalfOf != parameters.account) {
                return false;
            }
        } else if (context.selector == AavePool.repay) {
            if (AavePool.repay.onBehalfOf != parameters.account) {
                return false;
            }
        } else {
            return false;
        }

        let healthFactor = parameters.pool.getUserAccountData(parameters.account).healthFactor;
        return healthFactor >= parameters.minHealthFactor;
    }
}

How it Protects You

Failure ModeRail Defense
Bad MathThe Keeper calculates the wrong repay amount and leaves the position at risk. Blocked because HF is read directly from Aave during policy evaluation.
Front-runningMarket prices move while the tx is pending, making the collateral value drop. Blocked if the evaluated HF is too low.
Malicious ActionThe Keeper tries to withdraw collateral instead of supplying. Blocked because withdraw is not in the allowed function list.

Integration Steps

Compile: npx --package @steerprotocol/matador-cli matador-policy-cli compile aave-guard.matador -d ./out

Deploy: Install on your Smart Account.

Bot Logic: Your bot simply monitors HF. When it drops, it submits a repay transaction.

On this page