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

    Declaring aave_market as a caller supplied parameter, this takes whichever Aave market address is passed at execution time.

  2. 2·Get account data

    Reading the socket's overall position from the market wired in slot 0.0, this surfaces collateral, debt, borrow capacity, and health factor.

  3. 3·Take

    Taking supply_token as a second caller supplied parameter, this names the collateral asset the caller passes at execution.

  4. 4·Get price

    Oracle price for the supply_token in the market is read, giving the asset's value in the market's own units.

  5. 5·Get liquidation LTV

    Liquidation LTV for the supply_token in the market is read, giving the threshold at which the position becomes liquidatable.

  6. 6·Calculate proportional value

    A proportional calculation takes the liquidation LTV in slot 4.2 in basis points of the collateral figure in slot 1.1.0, deriving a ceiling figure.

  7. 7·Set

    Storing that ceiling as max_debt_before_liquidation, this names the highest debt the collateral can carry before liquidation.

  8. 8·Take

    Taking target_health_factor as a third caller supplied parameter, this names the health factor level the caller passes at execution.

  9. 9·Calculate

    Dividing max_debt_before_liquidation by target_health_factor sets a debt target scaled by the requested buffer.

  10. 10·Set

    Holding that quotient as target_debt, this names the debt level the position should be steered toward.

  11. 11·Compare two values

    Testing current debt in slot 1.1.1 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 comparison equaling true, so the following branch runs only when debt exceeds target.

  13. 13·Calculate

    Subtracting target_debt from current debt gives the excess to clear.

  14. 14·Set

    That result is stored as repay_amount, the amount of debt to pay down.

  15. 15·Calculate

    Dividing repay_amount by the price in slot 3.4 converts it into collateral units.

  16. 16·Set

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

  17. 17·Take

    Taking borrow_token as a fourth caller supplied parameter, this names the debt asset the caller passes at execution.

  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 the position 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 gives the shortfall to add.

  22. 22·Set

    That difference is stored as borrow_amount, the additional debt to take on.

  23. 23·Calculate

    Dividing borrow_amount by the price in slot 3.4 converts it into collateral units.

  24. 24·Set

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

  25. 25·Supply

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

  26. 26·Borrow

    Against that fresh collateral, borrow_amount of borrow_token is borrowed from the market, levering up toward target.

  27. 27·End block

    Closing the innermost open block, this ends the debt branch.

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
  • Loop at Target HF + Borrow Rate Entry & Exit Guard

    aave
    boolean
    evm
  • Loop WETH/USDC at Target HF

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

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

    database
    boolean
    aave
  • Swarm: Loop WETH/USDC at Target HF

    boolean
    aave
    evm

On other protocols · 3