epoch add
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -558,33 +558,75 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/// @notice Batch add to stakes for multiple users
|
/// @notice Re-enter/update the most recent epoch with new values and recalculated unlock percentage
|
||||||
/// @dev Only to be used by bots for edits
|
/// @param estDaysRemaining Estimated days remaining for the protocol
|
||||||
/// @param users Array of user addresses
|
/// @param currentTreasuryTvl Current treasury total value locked
|
||||||
/// @param amounts Array of stake amounts to ADD to a users bigStake
|
/// @param _paybackPercent Percentage multiplier for unlock calculation (scaled by 10000)
|
||||||
function batchUpdateUserStakes(address[] calldata users, uint256[] calldata amounts) external onlyBot {
|
/// @param _currentLiability Current total liability amount
|
||||||
require(users.length == amounts.length, "Array length mismatch");
|
function reenterEpoch(uint256 estDaysRemaining, uint256 currentTreasuryTvl, uint256 _paybackPercent, uint256 _currentLiability) external onlyOwner {
|
||||||
require(users.length > 0, "Empty arrays");
|
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");
|
|
||||||
|
|
||||||
// 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
|
uint256 epochId = currentEpochId - 1; // Most recent epoch
|
||||||
userBigStake[users[i]] += amounts[i];
|
|
||||||
|
uint256 unlockPercentage = 0;
|
||||||
|
// Calculate current ratio
|
||||||
|
if (_currentLiability > 0) {
|
||||||
|
uint256 currentRatio = (currentTreasuryTvl * 10000) / _currentLiability;
|
||||||
|
|
||||||
|
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
|
// Additional View Functions
|
||||||
|
|
||||||
/// @notice Get all withdraw stakes for a user
|
/// @notice Get all withdraw stakes for a user
|
||||||
|
|||||||
Reference in New Issue
Block a user