Skip to content

Commit

Permalink
Fix incorrect profit calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
matejos committed Oct 2, 2024
1 parent 5f4864a commit de13171
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions contracts/Compound3Liquidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ contract Compound3Liquidator is Ownable, IUniswapV3SwapCallback, IUniswapV3Flash
}

function _withdrawWethAndReturnProfit(uint256 wethBalanceBefore) internal returns (uint256, uint256) {
uint256 wethBalance = weth.balanceOf(address(this));
if (wethBalance > 0) {
weth.withdraw(wethBalance);
uint256 wethBalanceAfter = weth.balanceOf(address(this));
if (wethBalanceAfter > 0) {
weth.withdraw(wethBalanceAfter);
}

uint8 numberOfAssets = comet.numAssets();
Expand All @@ -292,7 +292,6 @@ contract Compound3Liquidator is Ownable, IUniswapV3SwapCallback, IUniswapV3Flash
}
}

uint256 wethBalanceAfter = address(this).balance;
uint256 profit = wethBalanceAfter - wethBalanceBefore;
uint256 profitUsd = (profit * comet.getPrice(wethAsset.priceFeed)) / wethAsset.scale;
profitReceiver.call{ value: profit }('');
Expand Down

0 comments on commit de13171

Please sign in to comment.