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.
Post-trade checks prevent bad repairs
The policy checks health factor after execution to guarantee the keeper cannot leave the position worse off.
The Policy
import "abis/IAavePool.json" as AavePool;
permission AaveHealthGuard -> 1.0.0 {
parameters: {
pool: address,
minHealthFactor: uint256
}
when: {
// 1. Pre-Check: Allow interaction with Aave Pool
context.target == parameters.pool,
// 2. Allow specific remedial actions
any {
AavePool.supply(amount: uint256, onBehalfOf: address, referralCode: uint16),
AavePool.repay(amount: uint256, interestRateMode: uint256, onBehalfOf: address)
},
// 3. Post-Check: The "Safety Net"
// Check health factor AFTER execution to ensure it improved
AavePool.getUserAccountData(user: context.account).healthFactor >= parameters.minHealthFactor
}
}How it Protects You
| Failure Mode | Rail Defense |
|---|---|
| Bad Math | The Keeper calculates the wrong repay amount and leaves the position at risk. Blocked because HF is checked after execution. |
| Front-running | Market prices move while the tx is pending, making the collateral value drop. Blocked if the resulting HF is too low. |
| Malicious Action | The Keeper tries to withdraw collateral instead of supplying. Blocked because withdraw is not in the allowed function list. |
Integration Steps
Compile: matador compile aave-guard.matador
Deploy: Install on your Smart Account.
Bot Logic: Your bot simply monitors HF. When it drops, it submits a repay transaction.