epoch add

This commit is contained in:
2025-10-09 17:57:55 +02:00
parent 74296bb16a
commit 8178311084
2 changed files with 95 additions and 43 deletions

File diff suppressed because one or more lines are too long

View File

@@ -558,33 +558,75 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
// }
// }
/// @notice Batch add to stakes for multiple users
/// @dev Only to be used by bots for edits
/// @param users Array of user addresses
/// @param amounts Array of stake amounts to ADD to a users bigStake
function batchUpdateUserStakes(address[] calldata users, uint256[] calldata amounts) external onlyBot {
require(users.length == amounts.length, "Array length mismatch");
require(users.length > 0, "Empty arrays");
/// @notice Re-enter/update the most recent epoch with new values and recalculated unlock percentage
/// @param estDaysRemaining Estimated days remaining for the protocol
/// @param currentTreasuryTvl Current treasury total value locked
/// @param _paybackPercent Percentage multiplier for unlock calculation (scaled by 10000)
/// @param _currentLiability Current total liability amount
function reenterEpoch(uint256 estDaysRemaining, uint256 currentTreasuryTvl, uint256 _paybackPercent, uint256 _currentLiability) external onlyOwner {
require(currentEpochId > 0, "No epochs to update");
for (uint256 i = 0; i < users.length; i++) {
require(users[i] != address(0), "Invalid address");
require(amounts[i] > 0, "Invalid amount");
uint256 epochId = currentEpochId - 1; // Most recent epoch
// Update totalBigStakes directly (add new)
totalBigStakes = totalBigStakes + amounts[i];
uint256 unlockPercentage = 0;
// Calculate current ratio
if (_currentLiability > 0) {
uint256 currentRatio = (currentTreasuryTvl * 10000) / _currentLiability;
// Add to original stake
userOriginalStake[users[i]] += amounts[i];
// Set last claimed epoch to current epoch
// userLastClaimedEpoch[users[i]] = currentEpochId; DONT Update
// Increment user's big stake
userBigStake[users[i]] += amounts[i];
if (epochId > 0) {
// Calculate unlock percentage BEFORE updating highest ratio
unlockPercentage = calculateUnlockPercentage(currentRatio, _paybackPercent);
}
// Update highest ratio AFTER calculating unlock percentage
if (currentRatio > highestRatio) {
highestRatio = currentRatio;
}
}
// Check that unlock percentage doesn't exceed maximum
require(unlockPercentage <= maxUnlockPercentage, "Unlock percentage high");
// Update the existing epoch entry
epochs[epochId] = Epoch({
estDaysRemaining: estDaysRemaining,
currentTreasuryTvl: currentTreasuryTvl,
totalLiability: _currentLiability,
paybackPercent: _paybackPercent,
unlockPercentage: unlockPercentage,
timestamp: block.timestamp
});
emit EpochEnded(epochId, currentTreasuryTvl, unlockPercentage, _paybackPercent);
}
// /// @notice Batch add to stakes for multiple users
// /// @dev Only to be used by bots for edits
// /// @param users Array of user addresses
// /// @param amounts Array of stake amounts to ADD to a users bigStake
// function batchUpdateUserStakes(address[] calldata users, uint256[] calldata amounts) external onlyBot {
// require(users.length == amounts.length, "Array length mismatch");
// require(users.length > 0, "Empty arrays");
// for (uint256 i = 0; i < users.length; i++) {
// require(users[i] != address(0), "Invalid address");
// require(amounts[i] > 0, "Invalid amount");
// // Update totalBigStakes directly (add new)
// totalBigStakes = totalBigStakes + amounts[i];
// // Add to original stake
// userOriginalStake[users[i]] += amounts[i];
// // Set last claimed epoch to current epoch
// // userLastClaimedEpoch[users[i]] = currentEpochId; DONT Update
// // Increment user's big stake
// userBigStake[users[i]] += amounts[i];
// }
// }
// Additional View Functions
/// @notice Get all withdraw stakes for a user