Changed order of operations
This commit is contained in:
@@ -328,16 +328,19 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
function endEpoch(uint256 estDaysRemaining, uint256 currentTreasuryTvl, uint256 _paybackPercent, uint256 _currentLiability) external onlyOwner {
|
function endEpoch(uint256 estDaysRemaining, uint256 currentTreasuryTvl, uint256 _paybackPercent, uint256 _currentLiability) external onlyOwner {
|
||||||
uint256 unlockPercentage = 0;
|
uint256 unlockPercentage = 0;
|
||||||
|
|
||||||
// Calculate current ratio and update highest ratio if necessary
|
// Calculate current ratio
|
||||||
if (_currentLiability > 0) {
|
if (_currentLiability > 0) {
|
||||||
uint256 currentRatio = (currentTreasuryTvl * 10000) / _currentLiability;
|
uint256 currentRatio = (currentTreasuryTvl * 10000) / _currentLiability;
|
||||||
if (currentRatio > highestRatio) {
|
|
||||||
highestRatio = currentRatio;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentEpochId > 0) {
|
if (currentEpochId > 0) {
|
||||||
|
// Calculate unlock percentage BEFORE updating highest ratio
|
||||||
unlockPercentage = calculateUnlockPercentage(currentRatio, _paybackPercent);
|
unlockPercentage = calculateUnlockPercentage(currentRatio, _paybackPercent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update highest ratio AFTER calculating unlock percentage
|
||||||
|
if (currentRatio > highestRatio) {
|
||||||
|
highestRatio = currentRatio;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that unlock percentage doesn't exceed maximum
|
// Check that unlock percentage doesn't exceed maximum
|
||||||
|
|||||||
Reference in New Issue
Block a user