Submitted by 0xAlix2
Users can call PositionAction::decreaseLever through a proxy, to Decrease the leverage of a position by taking out a credit flash loan to withdraw and sell collateral. After it is called, the flash loan lender sends the credit and calls onCreditFlashLoan, which handles all that logic. When doing so, users are supposed to swap their collateral withdrawn into debt tokens so that the flash loan can be repaid.
The protocol tries to handle the residual amount from the swap (swapped - paid debt), by trying to repay extra debt for the designated position, using:
However, this is invalid for 2 main reasons:
Add the following test in src/test/integration/PositionAction20.lever.t.sol:
Logs:
Rather than using the residual amount to repay excess debt (that might not even exist), transfer it to the designated residual recipient. Alternatively, check if the user still has any remaining debt. If they do, use the residual to repay it; otherwise, transfer the residual amount to the recipient.
DoS
amarcu (LoopFi) confirmed and commented:
0xAlix2 (warden) commented:
Koolex (judge) commented:
