
Aave · Reads onchain state
Reads the socket's overall position in an Aave market: collateral, debt, borrow capacity, and health factor. The pool aggregates every reserve you use into base-currency totals for collateral and debt, the amount still available to borrow, the position's weighted LTV and liquidation threshold, and the health factor at 18 decimals. This is the exact view the pool uses when it decides whether a borrow or withdraw is allowed and whether the position can be liquidated. Reach for it to gate any step that changes leverage: require the health factor stays above a floor, size a borrow from availableBorrows, or trigger a repay when debt drifts past a target.
Target Debt to Debt Delta



1·Take
Declares aave_market as a caller supplied parameter, taking whichever market address is passed at execution time.
2·Take
Declares target_debt as a second caller supplied parameter, the debt figure the caller wants measured against.
3·Get account data
Reads the socket's overall position in the market from slot 0.0, pulling collateral, debt, borrow capacity, and health factor.
4·Compare two values
Checks whether current debt in slot 2.1.1 is greater than the target_debt in slot 1.0, returning a boolean about debt sitting above target.
5·Set
Stores that comparison as debt_is_over_target, the flag recording which side of the target debt falls on.
6·Set
Initializes debt_delta to 0, seeding the running difference before either branch writes to it.
7·Predicate
Branches on debt_is_over_target being equal to true, entering the following block only when current debt exceeds target.
8·Calculate
Within that branch, subtracting the target_debt from current debt in slot 2.1.1 sizes how far debt overshoots.
9·Set
That overshoot is written into debt_delta, recording the amount above target.
10·Else branch
Opens the else branch for the case where debt sits at or below target.
11·Calculate
On this side, subtracting current debt in slot 2.1.1 from the target_debt sizes how far debt falls short.
12·Set
The shortfall is written into debt_delta, recording the amount below target.
13·End block
Closes the conditional block, rejoining a single path after either branch.
14·Bubble
Surfaces debt_is_over_target as an output, signaling whether debt is above or below the target.
15·Bubble
Surfaces debt_delta as an output, the absolute distance between current debt and the target.
On other protocols · 4