Closed scorpion9979 closed 3 years ago
Unfortunately, I cannot approve of this. The HifiFlashUniswapV2
is bloated already - applying the modifications brought about about by this PR would add too much complexity in a single contract. That complexity would percolate through the tests and the liquidator bot.
After some research I did this morning, I think that Aave would be a better choice when repay a borrow that was made with underlying as collateral. As per this article that compares flash loan providers (Aave, dYdX, Uniswap), Aave works best when you don't want to make a swap and you need multiple currency options. dYdX is ok too but as far as I know it's not running on Polygon.
By writing an Aave flash loan implementation, we would:
HifiFlashUniswapV2
contract and the tests.
Regarding liquidating USDC collateral, the following modifications needed to be applied to the flash-swap contract:
getRepayCollateralAmount(...)
function in flash-swap to enable different calculation for this special case.msg.sender
verification in flash-swap, as it previously required the msg sender address to be equal to the pair address of underlying and collateral computed usingpairFor(...)
. Since it's not possible to have a USDC-USDC pair, we needed to constrain this check to the case where the underlying token is not the same as the collateral to be liquidated.