Deleverage
Last updated
Last updated
Continuing from .
Deleverage enables users to reduce collateral exposure in a single step by using a flash loan to repay the borrowed asset.
Source token: the debt token to be repaid.
Destination token: the collateral token to be withdrawn.
By specifying the source token, the source token amount, and the destination token that the user wants to deleverage, the function will return the withdrawn destination token amount, the updated user portfolio, and the logics to be executed.
The logic should be composed by steps including:
Borrow a flash loan of the destination token
Swap the destination token for the source token
Repay the debt with the source token
Get the protocol token (aToken) from the user
Withdraw the destination token
Repay the flash loan with the destination token
To perform the logics, certain approvals need to be processed. You may refer to Estimate Router Data and Send Router Transaction for more details.