Borrow
Borrow

Aave · Acts onchain

Borrows an asset from an Aave market against collateral you have supplied. The pool lends the amount at the variable rate straight to the socket, opening or growing a variable debt position; it only succeeds while your health factor stays above one afterward. Set the amount to max to borrow the full capacity the market allows. Reach for it after a supply in the same transaction to build leverage, to fund a swap or deposit elsewhere with borrowed capital, or inside a flash loan block to convert a temporary loan into lasting debt. Pair it with account data so a predicate holds the resulting health factor above your floor.

Aave: Wind or Unwind Position

plug
boolean
aave
34actions
  1. 1·Take

    Declares supply_amount as a caller-supplied parameter whose value is provided at execution time.

  2. 2·Take

    Adds supply_token as a caller-supplied parameter naming the asset to supply.

  3. 3·Take

    Names aave_market as a caller-supplied parameter identifying the market used throughout.

  4. 4·Take

    Introduces borrow_amount as a caller-supplied parameter, the quantity to borrow.

  5. 5·Take

    Declares borrow_token as a caller-supplied parameter naming the asset to borrow.

  6. 6·Take

    Rounds out the inputs with is_winding, a caller-supplied flag that selects between the wind and unwind paths.

  7. 7·Predicate

    An if opens on the is_winding flag being equal to 1, entering the wind path when the caller set it true.

  8. 8·Flash loan

    Takes a flash loan of the supply_amount in the supply_token from the aave_market, to be repaid within this same transaction.

  9. 9·Set

    Saves the flash loan repayment obligation into wind_loan_owed for a later check.

  10. 10·Supply

    Supplies the supply_amount of the supply_token into the aave_market, minting aTokens to the socket as collateral.

  11. 11·Borrow

    Borrows the borrow_amount of the borrow_token from the aave_market against the collateral just supplied.

  12. 12·Get address

    Loads the solver address into a named value for use as a transfer destination.

  13. 13·Get token balance

    Reads the supply_token balance held by 0x4844...3a88 before routing.

  14. 14·Transfer tokens

    Sends the borrow_amount of the borrow_token to the solver to be routed.

  15. 15·Get solution

    Hands the transferred tokens to the solver for routing, then verifies the outcome.

  16. 16·Get token balance

    Reads the supply_token balance held by 0x4844...3a88 again after routing.

  17. 17·Calculate

    Subtracts the pre-routing balance from the post-routing balance to measure how much supply_token was gained.

  18. 18·Compare two values

    Checks whether that gain is greater than or equal to wind_loan_owed.

  19. 19·Predicate

    Requires that comparison to hold true, aborting the transaction if the gain does not cover the loan owed.

  20. 20·End block

    Closes the wind branch opened above.

  21. 21·Else branch

    Opens the else branch for the case where is_winding is not true, the unwind path.

  22. 22·Flash loan

    Takes a flash loan of the borrow_amount in the borrow_token from the aave_market, to be repaid within this same transaction.

  23. 23·Set

    Saves the flash loan repayment obligation into unwind_loan_owed for a later check.

  24. 24·Withdraw

    Withdraws the supply_amount of the supply_token from the aave_market back to the socket now that the borrow is covered by the flash loan.

  25. 25·Get address

    Loads the solver address into a named value for use as a transfer destination.

  26. 26·Get token balance

    Reads the borrow_token balance held by 0x4844...3a88 before routing.

  27. 27·Transfer tokens

    Sends the supply_amount of the supply_token to the solver to be routed.

  28. 28·Get solution

    Hands the transferred tokens to the solver for routing, then verifies the outcome.

  29. 29·Get token balance

    Reads the borrow_token balance held by 0x4844...3a88 again after routing.

  30. 30·Calculate

    Subtracts the pre-routing balance from the post-routing balance to measure how much borrow_token came back from routing.

  31. 31·Compare two values

    Checks whether that gain is greater than or equal to unwind_loan_owed.

  32. 32·Predicate

    Requires that comparison to hold true, aborting the transaction if the gain does not cover the loan owed.

  33. 33·End block

    Closes the unwind branch.

  34. 34·End block

    Closes the remaining open conditional block.

Take
Take
Take
Take
Take
Take
Flash loan from
Set to
Supply to
Borrow from
Get
Get balance of held by
Transfer to
Get solution
Get balance of held by
Calculate
Is
End block
Else
Flash loan from
Set to
Withdraw from
Get
Get balance of held by
Transfer to
Get solution
Get balance of held by
Calculate
Is
End block
End block
  • Aave: Wind or Unwind Position

    plug
    boolean
    aave
  • Wind

    plug
    aave
    evm
  • Wind or Unwind to Maintain Target HF

    plug
    aave
    math
  • Borrow + Weekly Repayments

    time
    aave
    evm
  • Loop WETH/USDC at Target HF

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

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

    database
    boolean
    aave
  • Borrow + Term Repayment Schedule

    time
    database
    boolean
  • Loop at Target HF + Borrow Rate Exit Guard

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

    aave
    boolean
    evm

On other protocols · 4