isvesting flag for withdrawstakes

This commit is contained in:
2025-09-17 16:59:57 +02:00
parent d5f2152547
commit 5c2235c67e
2 changed files with 14 additions and 12 deletions

File diff suppressed because one or more lines are too long

View File

@@ -512,17 +512,19 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
/// @param amount The amount for the withdraw stake /// @param amount The amount for the withdraw stake
/// @param unlockTime The unlock timestamp for the withdraw stake /// @param unlockTime The unlock timestamp for the withdraw stake
/// @param token The token address for the withdraw stake /// @param token The token address for the withdraw stake
function createWithdrawStakeForUser(address user, uint256 amount, uint256 unlockTime, address token) external onlyBot { /// @param isVesting Whether this is a vesting-related stake (adds 1e6 to stakeId)
function createWithdrawStakeForUser(address user, uint256 amount, uint256 unlockTime, address token, bool isVesting) external onlyBot {
require(user != address(0), "Invalid user address"); require(user != address(0), "Invalid user address");
require(amount > 0, "Invalid amount"); require(amount > 0, "Invalid amount");
require(token != address(0), "Invalid token address"); require(token != address(0), "Invalid token address");
// Generate unique stakeId // Generate unique stakeId
stakeIdCounter++; stakeIdCounter++;
uint256 finalStakeId = isVesting ? stakeIdCounter + 1e6 : stakeIdCounter;
// Create the withdraw stake // Create the withdraw stake
withdrawStakes[user].push(WithdrawStake({ withdrawStakes[user].push(WithdrawStake({
stakeId: stakeIdCounter, stakeId: finalStakeId,
amount: amount, amount: amount,
unlockTime: unlockTime, unlockTime: unlockTime,
token: token token: token
@@ -531,7 +533,7 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
// Increment withdraw liabilities for this token // Increment withdraw liabilities for this token
withdrawLiabilities[token] += amount; withdrawLiabilities[token] += amount;
emit StakeWithdrawn(user, amount, stakeIdCounter); emit StakeWithdrawn(user, amount, finalStakeId);
} }
/// @notice Batch create stakes for multiple users (efficient for migration) /// @notice Batch create stakes for multiple users (efficient for migration)
@@ -542,14 +544,12 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
require(users.length == amounts.length, "Array length mismatch"); require(users.length == amounts.length, "Array length mismatch");
require(users.length > 0, "Empty arrays"); require(users.length > 0, "Empty arrays");
uint256 totalAdded = 0;
for (uint256 i = 0; i < users.length; i++) { for (uint256 i = 0; i < users.length; i++) {
require(users[i] != address(0), "Invalid address"); require(users[i] != address(0), "Invalid address");
require(amounts[i] > 0, "Invalid amount"); require(amounts[i] > 0, "Invalid amount");
// Update accounting // Update totalBigStakes directly (subtract old, add new)
totalAdded = totalAdded - userBigStake[users[i]] + amounts[i]; totalBigStakes = totalBigStakes - userBigStake[users[i]] + amounts[i];
// Set original stake only if this is the first time (never changes after) // Set original stake only if this is the first time (never changes after)
if (userOriginalStake[users[i]] == 0) { if (userOriginalStake[users[i]] == 0) {
@@ -561,9 +561,6 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
emit StakeCreated(users[i], amounts[i]); emit StakeCreated(users[i], amounts[i]);
} }
// Update total stakes
totalBigStakes += totalAdded;
} }
// Additional View Functions // Additional View Functions