Collateral swap
Last updated
Last updated
Continuing from .
Collateral swap enables users to replace one collateral asset with another in a single step by using a flash loan.
Source token: the collateral token to be swapped from.
Destination token: the collateral token to be swapped for.
By specifying the source token, the source token amount, and the destination token, the function will return the destination token amount, the updated user portfolio, and the logics to be executed.
The logic should include:
Borrow a flash loan of the source token
Swap the source token for the destination token
Deposit the destination token
Return the destination protocol token (aToken) to the user
Get the source protocol token (aToken) from the user
Withdraw the source token
Repay the flash loan token with the source 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.