Aave Unified Protection: Multi-Strategy Automated Liquidation Defense with Reactive Smart Contracts

Never lose your DeFi position to liquidation again. The Aave Unified Protection system provides comprehensive automated risk management through a single contract deployment, offering users choice between collateral deposit, debt repayment, or combined protection strategies — all monitored continuously by Reactive Smart Contracts.
Introduction
DeFi lending has transformed finance by enabling permissionless borrowing and lending, but liquidation risk remains the sector's greatest user experience barrier. Traditional solutions force you to choose between manually monitoring positions 24/7 or accepting liquidation risk. The Aave Unified Protection System solves this comprehensively.
Built on Reactive Smart Contracts, this unified platform serves multiple users through a single contract deployment, offering subscription-based protection with flexible strategy selection. Users can choose collateral deposit, debt repayment, or combined protection — all automated and continuously monitored.
The Multi-Strategy Advantage
The Unified Protection approach provides three protection strategies:
Collateral Deposit Strategy: Automatically supplies additional collateral to improve health factor, ideal for users with available collateral tokens who want to maintain their debt exposure.
Debt Repayment Strategy: Automatically repays debt to reduce leverage and improve health factor, perfect for users who prefer deleveraging during volatile periods.
Combined Protection: Uses both strategies with user-defined preference order, providing comprehensive coverage that adapts to available assets and market conditions.
Universal Asset Support: Works with ANY asset supported by Aave's native oracle system — no need for external price feeds or custom configurations.
How Reactive Contracts Enable Unified Protection
The system creates comprehensive automation through:
Continuous Multi-User Monitoring: The Reactive Contract subscribes to CRON events, periodically checking ALL subscribed users' Aave positions against their individual thresholds.
Intelligent Strategy Selection: When a user's health factor drops below their safety threshold, the system automatically selects the appropriate protection strategy based on their subscription preferences.
Batch Processing Efficiency: Multiple users are processed in a single callback execution, optimizing gas costs and ensuring the system scales efficiently.
Automated Asset Management: Using Aave's native price oracle system, the system calculates precise amounts needed for either collateral addition or debt repayment.
Architecture Components
Reactive Contract
function react(LogRecord calldata log) external vmOnly {
if (log.topic_0 == cronTopic) {
if (processingActive) {
return; // Already processing, skip this cycle
}
bytes memory payload = abi.encodeWithSignature(
"checkAndProtectPositions(address)",
address(0)
);
processingActive = true;
emit Callback(SEPOLIA_CHAIN_ID, protectionManager, CALLBACK_GAS_LIMIT, payload);
} else if (log.topic_0 == PROTECTION_CYCLE_COMPLETED_TOPIC_0) {
processingActive = false;
emit ProtectionCompleted(block.timestamp);
}
}
Unified Callback Contract (Sepolia)
AaveUnifiedProtectionCallback handles all Aave interactions, user subscriptions, and protection execution:
function checkAndProtectPositions(address) external authorizedSenderOnly {
uint256 totalUsersChecked = 0;
uint256 protectionsExecuted = 0;
for (uint256 i = 0; i < activeUsers.length; i++) {
address user = activeUsers[i];
UserProtection memory protection = userProtections[user];
if (!protection.isActive) continue;
totalUsersChecked++;
try this._checkAndProtectUser(user, protection) returns (bool wasProtected) {
if (wasProtected) {
protectionsExecuted++;
}
} catch {
emit ProtectionFailed(user, lendingPool, "Unexpected error during protection check");
}
}
emit ProtectionCycleCompleted(block.timestamp, totalUsersChecked, protectionsExecuted);
}
Protection Strategies Implementation
Combined Protection Strategy
The most sophisticated approach attempts both strategies based on user preferences:
else if (protection.protectionType == ProtectionType.BOTH) {
if (protection.preferDebtRepayment) {
protectionExecuted = _executeDebtRepayment(user, protection, currentHealthFactor);
if (!protectionExecuted) {
protectionExecuted = _executeCollateralProtection(user, protection, currentHealthFactor);
}
} else {
protectionExecuted = _executeCollateralProtection(user, protection, currentHealthFactor);
if (!protectionExecuted) {
protectionExecuted = _executeDebtRepayment(user, protection, currentHealthFactor);
}
}
}
Universal Asset Support Through Aave's Oracle
function _getAssetPrice(address asset) internal view returns (uint256) {
address priceOracleAddress = ILendingPoolAddressesProvider(addressesProvider).getPriceOracle();
return IPriceOracleGetter(priceOracleAddress).getAssetPrice(asset);
}
function _validateAssetSupported(address asset) internal view returns (bool) {
try this.getAssetPrice(asset) returns (uint256 price) {
return price > 0;
} catch {
return false;
}
}
Subscription Management
Users subscribe by calling a single function with their protection preferences:
function subscribeToProtection(
ProtectionType _protectionType,
uint256 _healthFactorThreshold,
uint256 _targetHealthFactor,
address _collateralAsset,
address _debtAsset,
bool _preferDebtRepayment
) external {
require(_healthFactorThreshold > 0, "Invalid threshold");
require(_targetHealthFactor > _healthFactorThreshold, "Target must be higher than threshold");
require(_validateAssetSupported(_collateralAsset), "Collateral asset not supported by Aave");
require(_validateAssetSupported(_debtAsset), "Debt asset not supported by Aave");
UserProtection storage protection = userProtections[msg.sender];
if (!protection.isActive) {
activeUsers.push(msg.sender);
}
protection.isActive = true;
protection.protectionType = _protectionType;
protection.healthFactorThreshold = _healthFactorThreshold;
protection.targetHealthFactor = _targetHealthFactor;
protection.collateralAsset = _collateralAsset;
protection.debtAsset = _debtAsset;
protection.preferDebtRepayment = _preferDebtRepayment;
emit UserSubscribed(msg.sender, _protectionType, _healthFactorThreshold, _targetHealthFactor, _collateralAsset, _debtAsset);
}
Setup and Configuration
Contract Deployment
Deploy the unified callback contract:
forge create --broadcast --rpc-url $SEPOLIA_RPC --private-key $DESTINATION_PRIVATE_KEY \
src/demos/aave-unified-protection/AaveUnifiedProtectionCallback.sol:AaveUnifiedProtectionCallback \
--value 0.01ether --constructor-args $DESTINATION_CALLBACK_PROXY_ADDR $LENDING_POOL $PROTOCOL_DATA_PROVIDER $ADDRESSES_PROVIDER
Deploy the reactive monitoring contract:
forge create --legacy --broadcast --rpc-url $REACTIVE_RPC --private-key $REACTIVE_PRIVATE_KEY \
src/demos/aave-unified-protection/AaveUnifiedProtectionReactive.sol:AaveUnifiedProtectionReactive \
--value 0.01ether --constructor-args $CALLBACK_ADDR $SYSTEM_CONTRACT_ADDR $CRON_TOPIC
Protection Subscription Examples
Collateral-Only Protection:
cast send $CALLBACK_ADDR 'subscribeToProtection(uint8,uint256,uint256,address,address,bool)' \
--rpc-url $SEPOLIA_RPC --private-key $USER_PRIVATE_KEY \
0 1200000000000000000 1500000000000000000 $LINK_TOKEN $USDC_TOKEN false
Combined Protection (Prefer Debt Repayment):
cast send $CALLBACK_ADDR 'subscribeToProtection(uint8,uint256,uint256,address,address,bool)' \
--rpc-url $SEPOLIA_RPC --private-key $USER_PRIVATE_KEY \
2 1200000000000000000 1500000000000000000 $LINK_TOKEN $USDC_TOKEN true
Asset Authorization
# Approve collateral asset
cast send <COLLATERAL_ASSET> 'approve(address,uint256)' \
--rpc-url $SEPOLIA_RPC --private-key $USER_PRIVATE_KEY \
$CALLBACK_ADDR <AMOUNT>
# Approve debt asset
cast send <DEBT_ASSET> 'approve(address,uint256)' \
--rpc-url $SEPOLIA_RPC --private-key $USER_PRIVATE_KEY \
$CALLBACK_ADDR <AMOUNT>
Supported Assets (Aave V3 Sepolia)
Symbol | Address | Use Case |
---|---|---|
DAI | 0xFF34B3d4Aee8ddCd6F9AfffB6Fe49bD371b8a357 | Stable debt repayment |
LINK | 0xf8Fb3713D459D7C1018BD0A49D19b4C44290EBE5 | Volatile collateral |
USDC | 0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8 | Stable debt/collateral |
WETH | 0xC558DBdD856501FCd9aaF1E62eaE57A9F0629a3C | Primary collateral |
Key Events
event UserSubscribed(
address indexed user,
ProtectionType protectionType,
uint256 healthFactorThreshold,
uint256 targetHealthFactor,
address collateralAsset,
address debtAsset
);
event ProtectionExecuted(
address indexed user,
address indexed lendingPool,
string protectionMethod,
address asset,
uint256 amount,
uint256 newHealthFactor
);
event ProtectionCycleCompleted(
uint256 timestamp,
uint256 totalUsersChecked,
uint256 protectionsExecuted
);
Why Unified Protection Matters
For individual users, this eliminates the complexity of choosing between protection strategies and deploying individual contracts. Users get comprehensive coverage with flexible strategy selection through a single subscription.
For the DeFi ecosystem, this demonstrates how Reactive Smart Contracts can create sophisticated automation platforms that serve multiple users efficiently while maintaining personalized protection parameters.
The Unified Protection system makes sophisticated DeFi automation accessible to everyone through simple subscription management, comprehensive multi-strategy coverage, and efficient shared infrastructure.
About Reactive Network
The Reactive Network, pioneered by PARSIQ, ushers in a new wave of blockchain innovation through its Reactive Smart Contracts (RSCs). These advanced contracts can autonomously execute based on specific on-chain events, eliminating the need for off-chain computation and heralding a seamless cross-chain ecosystem vital for Web3’s growth.
Central to this breakthrough is the Inversion of Control (IoC) framework, which redefines smart contracts and decentralized applications (DApps) by imbuing them with unparalleled autonomy, efficiency, and interactivity. By marrying RSCs with IoC, Reactive Network is setting the stage for a transformative blockchain era, characterized by enhanced interoperability and the robust, user-friendly foundation Web3 demands.
Website | Blog | Twitter | Telegram | Discord | Docs