Skip to content

Commit 27d7883

Browse files
committed
fix: flashLoanAmount calculation
1 parent ecf996c commit 27d7883

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

contracts/Liquidator.sol

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ contract Liquidator is Ownable {
275275
returns (
276276
address tokenOut,
277277
uint256 optimalAmount,
278-
uint256 flashLoanAmount,
279278
uint256 repaidAmount,
279+
uint256 flashLoanAmount,
280280
bool isOptimalRepayable
281281
)
282282
{
@@ -289,7 +289,7 @@ contract Liquidator is Ownable {
289289

290290
(optimalAmount, repaidAmount, isOptimalRepayable) =
291291
_getOptimalAmount(creditAccount, tokenOut, hfOptimal, creditManager, priceOracle);
292-
flashLoanAmount = priceOracle.convert(optimalAmount, tokenOut, creditManager.underlying());
292+
flashLoanAmount = _getChargedAmount(repaidAmount, creditManager) * 1005 / 1000;
293293
}
294294

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

355+
function _getChargedAmount(uint256 repaidAmount, ICreditManagerV3 creditManager) internal view returns (uint256) {
356+
(, uint256 feeLiquidation,,,) = creditManager.fees();
357+
uint256 partialFeeLiquidation =
358+
feeLiquidation * IPartialLiquidationBotV3(partialLiquidationBot).feeScaleFactor() / PERCENTAGE_FACTOR;
359+
return repaidAmount * PERCENTAGE_FACTOR / (PERCENTAGE_FACTOR - partialFeeLiquidation);
360+
}
361+
355362
function _adjustToDebtLimits(
356363
ICreditManagerV3 creditManager,
357364
uint256 optimalAmount,

contracts/interfaces/ILiquidator.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ interface ILiquidator {
4848
returns (
4949
address tokenOut,
5050
uint256 optimalAmount,
51-
uint256 flashLoanAmount,
5251
uint256 repaidAmount,
52+
uint256 flashLoanAmount,
5353
bool isOptimalRepayable
5454
);
5555

0 commit comments

Comments
 (0)