
Aave · Acts onchain
Withdraws a supplied asset from an Aave market back to the socket. The pool burns aTokens and returns the underlying, reporting the amount withdrawn. Set the amount to max to withdraw the full supplied balance including accrued interest. The pool refuses a withdrawal that would drop the health factor below one. Reach for it to exit a lending position, to free collateral after a repay earlier in the transaction, or to pull funds that a following swap or deposit needs, coiling the withdrawn amount into the next step so the exact figure flows through.
Aave: Wind or Unwind Position



1·Take
Declares supply_amount as a caller-supplied parameter whose value is provided at execution time.
2·Take
Adds supply_token as a caller-supplied parameter naming the asset to supply.
3·Take
Names aave_market as a caller-supplied parameter identifying the market used throughout.
4·Take
Introduces borrow_amount as a caller-supplied parameter, the quantity to borrow.
5·Take
Declares borrow_token as a caller-supplied parameter naming the asset to borrow.
6·Take
Rounds out the inputs with is_winding, a caller-supplied flag that selects between the wind and unwind paths.
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·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·Set
Saves the flash loan repayment obligation into wind_loan_owed for a later check.
10·Supply
Supplies the supply_amount of the supply_token into the aave_market, minting aTokens to the socket as collateral.
11·Borrow
Borrows the borrow_amount of the borrow_token from the aave_market against the collateral just supplied.
12·Get address
Loads the solver address into a named value for use as a transfer destination.
13·Get token balance
Reads the supply_token balance held by 0x4844...3a88 before routing.
14·Transfer tokens
Sends the borrow_amount of the borrow_token to the solver to be routed.
15·Get solution
Hands the transferred tokens to the solver for routing, then verifies the outcome.
16·Get token balance
Reads the supply_token balance held by 0x4844...3a88 again after routing.
17·Calculate
Subtracts the pre-routing balance from the post-routing balance to measure how much supply_token was gained.
18·Compare two values
Checks whether that gain is greater than or equal to wind_loan_owed.
19·Predicate
Requires that comparison to hold true, aborting the transaction if the gain does not cover the loan owed.
20·End block
Closes the wind branch opened above.
21·Else branch
Opens the else branch for the case where is_winding is not true, the unwind path.
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·Set
Saves the flash loan repayment obligation into unwind_loan_owed for a later check.
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·Get address
Loads the solver address into a named value for use as a transfer destination.
26·Get token balance
Reads the borrow_token balance held by 0x4844...3a88 before routing.
27·Transfer tokens
Sends the supply_amount of the supply_token to the solver to be routed.
28·Get solution
Hands the transferred tokens to the solver for routing, then verifies the outcome.
29·Get token balance
Reads the borrow_token balance held by 0x4844...3a88 again after routing.
30·Calculate
Subtracts the pre-routing balance from the post-routing balance to measure how much borrow_token came back from routing.
31·Compare two values
Checks whether that gain is greater than or equal to unwind_loan_owed.
32·Predicate
Requires that comparison to hold true, aborting the transaction if the gain does not cover the loan owed.
33·End block
Closes the unwind branch.
34·End block
Closes the remaining open conditional block.
On other protocols · 5