Close
Last updated
Last updated
Continuing from .
Close enables users to empty all positions in a single step by using a flash loan to repay borrowed assets and withdraw deposited assets.
Collateral token: the collateral token to be withdrawn.
Debt token: the debt token to be repaid.
Withdrawal token: the user-specified token swapped from the collateral token.
By specifying the withdrawal token that the user wants to receive, the function will return the remaining withdrawn token amount, the updated user portfolio, and the logics to be executed.
The logics should include:
Borrow a flash loan of the withdrawal token
Swap the withdrawal token for the debt tokens
Repay the debt with the debt tokens
Get the protocol tokens (aToken) from the user
Withdraw the collateral tokens
Swap the collateral tokens for the withdrawal token
Repay the flash loan with the withdrawal token
Return the remained withdrawal token to the user
To perform the logics, certain approvals need to be processed. You may refer to Estimate Router Data and Send Router Transaction for more details.