Get liquidation LTV
Get liquidation LTV

Aave · Reads onchain state

Reads the liquidation threshold of an asset in an Aave market. The threshold is decoded from the reserve configuration in basis points: the debt-to-collateral ratio at which a position backed by this asset becomes liquidatable. It sits above the max LTV, and the gap between them is the cushion a position has after borrowing to the limit. Reach for it when computing how far price can move before liquidation, or to size a borrow or repay so a predicate keeps the position a chosen distance below the threshold in the same transaction.

Wind or Unwind to Maintain Target HF

plug
aave
math
27actions
  1. 1·Take

    Declares aave_market as a caller supplied parameter, taking whichever Aave market address is passed at execution time.

  2. 2·Get account data

    Reads the socket's overall position in that market from the market wired in slot 0.0, surfacing collateral, debt, borrow capacity, and health factor.

  3. 3·Take

    Declares supply_token as a second caller supplied parameter, the collateral asset the caller names.

  4. 4·Get price

    Reads the oracle price the market assigns to supply_token in that same market.

  5. 5·Get liquidation LTV

    Pulls the liquidation LTV of supply_token in the market, the threshold at which the position becomes liquidatable.

  6. 6·Calculate proportional value

    Taking the liquidation LTV in basis points of the collateral figure from the account data, this derives the debt ceiling before liquidation.

  7. 7·Set

    Storing that ceiling as max_debt_before_liquidation, this names the maximum debt the collateral can carry.

  8. 8·Take

    Declares target_health_factor as a third caller supplied parameter, the buffer divisor supplied at execution time.

  9. 9·Calculate

    Dividing max_debt_before_liquidation by target_health_factor sets a debt target under the ceiling.

  10. 10·Set

    Holding that quotient as target_debt, this names the debt level the plug steers toward.

  11. 11·Compare two values

    Comparing current debt from the account data against target_debt with a greater than operator, this returns a boolean about debt sitting above target.

  12. 12·Predicate

    A predicate opens on that boolean being true, so the following branch runs only when debt exceeds target.

  13. 13·Calculate

    Subtracting target_debt from current debt sizes the excess to clear.

  14. 14·Set

    That excess is stored as repay_amount, the debt to retire on this side.

  15. 15·Calculate

    Dividing repay_amount by the supply_token price converts the excess into collateral units.

  16. 16·Set

    The quotient is saved as withdraw_amount, the collateral to pull once debt is cleared.

  17. 17·Take

    Declares borrow_token as a fourth caller supplied parameter, the debt asset the caller names.

  18. 18·Repay

    Repaying repay_amount of borrow_token to the market from the socket's balance clears the excess debt.

  19. 19·Withdraw

    Withdrawing withdraw_amount of supply_token from the market deleverages toward target.

  20. 20·Else branch

    Opening the else branch, this defines what runs when debt is at or below target.

  21. 21·Calculate

    Subtracting current debt from target_debt sizes the shortfall to add.

  22. 22·Set

    That shortfall is stored as borrow_amount, the debt to add on this side.

  23. 23·Calculate

    Dividing borrow_amount by the supply_token price converts the shortfall into collateral units.

  24. 24·Set

    The quotient is held as supply_amount, the collateral to add before borrowing.

  25. 25·Supply

    Supplying supply_amount of supply_token to the market mints aTokens to the wallet.

  26. 26·Borrow

    Borrowing borrow_amount of borrow_token from the market against the fresh collateral levers up toward target.

  27. 27·End block

    Closing the innermost open block, this ends the conditional opened above.

Take
Get data in
Take
Get price of in
Get liquidation LTV of in
Calculate of
Set to
Take
Calculate
Set to
Is
Calculate
Set to
Calculate
Set to
Take
Repay to
Withdraw from
Else
Calculate
Set to
Calculate
Set to
Supply to
Borrow from
End block
  • Wind or Unwind to Maintain Target HF

    plug
    aave
    math
  • Swarm: Loop WETH/USDC at Target HF

    boolean
    aave
    evm
  • Loop at Target HF + Borrow Rate Exit Guard

    database
    boolean
    aave
  • Loop at Target HF + Trailing Stop Loss

    database
    boolean
    aave
  • Loop WETH/USDC at Target HF

    aave
    evm
    boolean
  • Loop at Target HF + Borrow Rate Entry & Exit Guard

    aave
    boolean
    evm

On other protocols · 3