Skip to content

Commit

Permalink
feat(flash-swap): added basic USDC repay logic
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpion9979 committed Oct 27, 2021
1 parent 8df2d9f commit d631d8e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/flash-swap/contracts/uniswap-v2/HifiFlashUniswapV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ contract HifiFlashUniswapV2 is IHifiFlashUniswapV2 {
uint256 repayCollateralAmount;
RepayType repayType;
uint256 seizedCollateralAmount;
uint256 swapFeeUnderlyingAmount;
address swapToken;
IErc20 underlying;
uint256 underlyingAmount;
Expand Down Expand Up @@ -189,6 +190,21 @@ contract HifiFlashUniswapV2 is IHifiFlashUniswapV2 {

if (vars.seizedCollateralAmount > vars.repayCollateralAmount) {
vars.profitCollateralAmount = vars.seizedCollateralAmount - vars.repayCollateralAmount;
} else if (address(vars.collateral) != address(vars.underlying)) {
uint112 collateralReserves;
uint112 underlyingReserves;
IUniswapV2Pair pair = IUniswapV2Pair(msg.sender);
if (pair.token0() == address(vars.underlying)) {
(underlyingReserves, collateralReserves, ) = pair.getReserves();
} else {
(collateralReserves, underlyingReserves, ) = pair.getReserves();
}
uint256 numerator;
uint256 denominator;
numerator = (vars.repayCollateralAmount - vars.seizedCollateralAmount) * underlyingReserves;
denominator = (collateralReserves + vars.seizedCollateralAmount);
vars.swapFeeUnderlyingAmount = numerator / denominator + 1;
vars.repayCollateralAmount = vars.seizedCollateralAmount;
}
if (vars.profitCollateralAmount < vars.minProfit) {
revert HifiFlashUniswapV2__InsufficientProfit(
Expand Down

0 comments on commit d631d8e

Please sign in to comment.