Skip to content

Commit

Permalink
fix: flashLoanAmount calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
doomsower committed May 27, 2024
1 parent ecf996c commit 27d7883
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions contracts/Liquidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ contract Liquidator is Ownable {
returns (
address tokenOut,
uint256 optimalAmount,
uint256 flashLoanAmount,
uint256 repaidAmount,
uint256 flashLoanAmount,
bool isOptimalRepayable
)
{
Expand All @@ -289,7 +289,7 @@ contract Liquidator is Ownable {

(optimalAmount, repaidAmount, isOptimalRepayable) =
_getOptimalAmount(creditAccount, tokenOut, hfOptimal, creditManager, priceOracle);
flashLoanAmount = priceOracle.convert(optimalAmount, tokenOut, creditManager.underlying());
flashLoanAmount = _getChargedAmount(repaidAmount, creditManager) * 1005 / 1000;
}

function _getBestTokenOut(address creditAccount, ICreditManagerV3 creditManager, IPriceOracleV3 priceOracle)
Expand Down Expand Up @@ -352,6 +352,13 @@ contract Liquidator is Ownable {
return _adjustToDebtLimits(creditManager, optimalAmount, repaidAmount, CreditLogic.calcTotalDebt(cdd));
}

function _getChargedAmount(uint256 repaidAmount, ICreditManagerV3 creditManager) internal view returns (uint256) {
(, uint256 feeLiquidation,,,) = creditManager.fees();
uint256 partialFeeLiquidation =
feeLiquidation * IPartialLiquidationBotV3(partialLiquidationBot).feeScaleFactor() / PERCENTAGE_FACTOR;
return repaidAmount * PERCENTAGE_FACTOR / (PERCENTAGE_FACTOR - partialFeeLiquidation);
}

function _adjustToDebtLimits(
ICreditManagerV3 creditManager,
uint256 optimalAmount,
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ILiquidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ interface ILiquidator {
returns (
address tokenOut,
uint256 optimalAmount,
uint256 flashLoanAmount,
uint256 repaidAmount,
uint256 flashLoanAmount,
bool isOptimalRepayable
);

Expand Down

0 comments on commit 27d7883

Please sign in to comment.