-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(flash-swap): support liquidating vaults with underlying as collateral #64
Conversation
6625f4a
to
59db094
Compare
…apV2" chore: update flash contract deployers to use the latest contract names chore(tasks): update flash contract deployers to use the latest contract names refactor(flash-swap): "HifiFlashUniswapV2Underlying" into "UnderlyingFlashUniswapV2" refactor(flash-swap): "HifiFlashUniswapV2Utils" into "FlashUtils" test(flash-swap): update tests to use the latest contract names
…ngFlashUniswapV2" chore(amm,flash-swap,proxy-target): use "old" and "new" prefixes instead of "pre" and "post" chore(flash-swap): better explain the role of subsidizer in the "uniswapV2Call" function refactor(errors): "FlashBorrowWrongToken" to "FlashBorrowOtherToken" refactor(flash-swap): "bot" to "subsidizer" refactor(flash-swap): "collateral" to "otherToken" refactor(flash-swap): "collateralRepayAmount" to "repayCollateralAmount" refactor(flash-swap): delete "collateralAmount" arg in "FlashBorrowCollateral" custom err refactor(flash-swap): delete superfluous "vars.swapToken" var refactor(flash-swap): "FlashLiquidateBorrow" event to "FlashSwapCollateralAndLiquidateBorrow" refactor(flash-swap): "FlashLiquidateBorrow" event to "FlashSwapUnderlyingAndLiquidateBorrow" refactor(flash-swap): "getCollateralAndUnderlyingAmount" to "getOtherTokenAndUnderlyingAmount" refactor(flash-swap): "getRepayCollateralAmount" to "getRepayUnderlyingAmount" refactor(flash-swap): "overshootCollateralAmount" to "shortfallUnderlyingAmount" refactor(flash-swap): import "IHToken" in "FlashUtils.sol" test(flash-swap): order vars alphabetically test(flash-swap): rename "usdcRepayFeeAmount" var to "usdcFeeAmount"
…2" tests test(flash-swap): import "LIQUIDATION_INCENTIVES" to set liquidation incentives for USDC/ WBTC
I refactored pretty much everything. For a detailed log, see the commit messages. Here's the high level:
You can add your review @scorpion9979 and then I will merge the PR. |
packages/flash-swap/test/integration/collateralFlashUniswapV2/CollateralFlashUniswapV2.ts
Outdated
Show resolved
Hide resolved
packages/flash-swap/test/integration/collateralFlashUniswapV2/CollateralFlashUniswapV2.ts
Outdated
Show resolved
Hide resolved
packages/flash-swap/test/integration/underlyingFlashUniswapV2/effects/uniswapV2Call.ts
Outdated
Show resolved
Hide resolved
After another review, I noticed three other issues:
if (vars.repayUnderlyingAmount > vars.seizedUnderlyingAmount) Any surplus of underlying should be relayed to the caller, just like we're doing in Already started working on fixes. |
…nderlyingAmount" docs(flash-swap): better formulate the NatSpec comments for "getRepayUnderlyingAmount" test(flash-swap): add time-bound tests for "UnderlyingFlashUniswapV2" test(flash-swap): delete price-related tests for "UnderlyingFlashUniswapV2" test(flash-swap): refer to the "pair contract" as "UniswapV2Pair contract" in descriptors test(flash-swap): rename "bumpPoolReserves" to "increasePoolReserves" test(flash-swap): rename "collateralAmount" to "swapCollateralAmount" test(flash-swap): rename "repayHUsdcAmount" to "repayAmount" test(flash-swap): rename "underlyingAmount" to "swapUnderlyingAmount"
This was a hairy refactor ... I made progress with the latest commit, but the following test cases are still not written:
I'll handle them tomorrow. |
packages/flash-swap/contracts/uniswap-v2/UnderlyingFlashUniswapV2.sol
Outdated
Show resolved
Hide resolved
docs(flash-swap): rewrite the @notice for "liquidateBorrowInternal" function refactor(flash-swap): emit "profitUnderlyingAmount" and "subsidizedUnderlyingAmont" in event refactor(flash-swap): rename "shortfallUnderlyingAmount" to "subsidizedUnderlyingAmount" refactor(flash-swap): rename "surplusUnderlyingAmount" to "profitUnderlyingAmount" test(flash-swap): erc-20 approve to "MaxUint256" test(flash-swap): refer to USDC as "underlying" in variable names test(flash-swap): rename "repayAmount" to "repayHTokenAmount" test(flash-swap): when the repay underlying amount is less than the seized underlying amount
packages/flash-swap/test/integration/underlyingFlashUniswapV2/effects/uniswapV2Call.ts
Outdated
Show resolved
Hide resolved
6ebee5b
to
65a497b
Compare
test(flash-swap): remove redundant debug console logs
65a497b
to
190e0ec
Compare
247feb2
to
5ced780
Compare
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.