From 3ba0e3c61f17eae0c0b2625a80a4c841a247f247 Mon Sep 17 00:00:00 2001 From: Antonio Guilherme Ferreira Viggiano Date: Thu, 4 Jul 2024 08:49:10 -0300 Subject: [PATCH] c4-019 Refactor fee calculation in AccountingLibrary.getCashAmountOut --- src/libraries/AccountingLibrary.sol | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libraries/AccountingLibrary.sol b/src/libraries/AccountingLibrary.sol index aee76deb..6c945681 100644 --- a/src/libraries/AccountingLibrary.sol +++ b/src/libraries/AccountingLibrary.sol @@ -190,12 +190,11 @@ library AccountingLibrary { uint256 tenor ) internal view returns (uint256 cashAmountOut, uint256 fees) { uint256 maxCashAmountOut = Math.mulDivDown(creditAmountIn, PERCENT, PERCENT + ratePerTenor); + fees = getSwapFee(state, maxCashAmountOut, tenor); if (creditAmountIn == maxCredit) { // no credit fractionalization - fees = getSwapFee(state, maxCashAmountOut, tenor); - if (fees > maxCashAmountOut) { revert Errors.NOT_ENOUGH_CASH(maxCashAmountOut, fees); } @@ -204,7 +203,7 @@ library AccountingLibrary { } else if (creditAmountIn < maxCredit) { // credit fractionalization - fees = getSwapFee(state, maxCashAmountOut, tenor) + state.feeConfig.fragmentationFee; + fees += state.feeConfig.fragmentationFee; if (fees > maxCashAmountOut) { revert Errors.NOT_ENOUGH_CASH(maxCashAmountOut, fees);