@@ -55,6 +55,9 @@ abstract contract BaseDynamicFeeManager is
5555 // Max. amount for fee entries
5656 uint256 public constant MAX_FEE_AMOUNT = 30 ;
5757
58+ // Min. amount for swap / liquify
59+ uint256 public constant MIN_SWAP_OR_LIQUIFY_AMOUNT = 1 ether ;
60+
5861 // Fee divider
5962 uint256 internal constant FEE_DIVIDER = 100_000 ;
6063
@@ -65,11 +68,11 @@ abstract contract BaseDynamicFeeManager is
6568 // List of all currently added fees
6669 FeeEntry[] internal feeEntries;
6770
68- // Mapping id to current liquify or swap amounts
71+ // Mapping id to current swap or liquify amounts
6972 mapping (bytes32 => uint256 ) internal feeEntryAmounts;
7073
7174 // Fees enabled state
72- bool private _feesEnabled = false ;
75+ bool internal feesEnabled_ = false ;
7376
7477 // Pancake Router address
7578 IPancakeRouter02 private _pancakeRouter =
@@ -134,7 +137,7 @@ abstract contract BaseDynamicFeeManager is
134137 }
135138
136139 function setFeesEnabled (bool value ) external override onlyRole (ADMIN) {
137- _feesEnabled = value;
140+ feesEnabled_ = value;
138141
139142 emit FeeEnabledUpdated (value);
140143 }
@@ -251,7 +254,7 @@ abstract contract BaseDynamicFeeManager is
251254 }
252255
253256 function feesEnabled () public view override returns (bool ) {
254- return _feesEnabled ;
257+ return feesEnabled_ ;
255258 }
256259
257260 function pancakeRouter ()
@@ -472,17 +475,24 @@ abstract contract BaseDynamicFeeManager is
472475 /**
473476 * Returns the amount used for swap / liquify based on volume percentage for swap / liquify
474477 *
478+ * @param feeId bytes32 - Fee entry id
475479 * @param swapOrLiquifyAmount uint256 - Fee entry swap or liquify amount
476480 * @param percentageVolume uint256 - Volume percentage for swap / liquify
477481 * @param pancakePairAddress address - Pancakeswap pair address to use for volume
478482 *
479483 * @return amount uint256 - Amount used for swap / liquify
480484 */
481485 function _getSwapOrLiquifyAmount (
486+ bytes32 feeId ,
482487 uint256 swapOrLiquifyAmount ,
483488 uint256 percentageVolume ,
484489 address pancakePairAddress
485490 ) internal view returns (uint256 amount ) {
491+ // If no percentage and fixed amount is set, use balance
492+ if (percentageVolume == 0 && swapOrLiquifyAmount == 0 ) {
493+ return feeEntryAmounts[feeId];
494+ }
495+
486496 if (pancakePairAddress == address (0 ) || percentageVolume == 0 ) {
487497 return swapOrLiquifyAmount;
488498 }
@@ -495,6 +505,16 @@ abstract contract BaseDynamicFeeManager is
495505 uint256 percentualAmount = (pancakePairTokenBalance *
496506 percentageVolume) / 100 ;
497507
508+ // If swap or liquify amount is zero, and percentual amount is
509+ // higher than collected amount, return collected amount, otherwise
510+ // return percentual amount
511+ if (swapOrLiquifyAmount == 0 ) {
512+ return
513+ percentualAmount > feeEntryAmounts[feeId]
514+ ? feeEntryAmounts[feeId]
515+ : percentualAmount;
516+ }
517+
498518 // Do not exceed swap or liquify amount from fee entry
499519 if (percentualAmount >= swapOrLiquifyAmount) {
500520 return swapOrLiquifyAmount;
0 commit comments