marketplace min and multiple withdrawStakes

This commit is contained in:
2025-09-14 15:32:50 +02:00
parent 25e6149917
commit 4f8f062f35
2 changed files with 36 additions and 65 deletions

File diff suppressed because one or more lines are too long

View File

@@ -415,9 +415,14 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
}
/// @notice Withdraw claimed funds after unlock period
function withdrawStake(uint256 stakeId) external nonReentrant {
function withdrawStake(uint256[] calldata stakeIds) external nonReentrant {
WithdrawStake[] storage userStakes = withdrawStakes[msg.sender];
require(userStakes.length > 0, "No stakes available");
require(stakeIds.length > 0, "No stake IDs provided");
for (uint256 j = 0; j < stakeIds.length; j++) {
uint256 stakeId = stakeIds[j];
bool found = false;
for (uint256 i = 0; i < userStakes.length; i++) {
WithdrawStake storage stake = userStakes[i];
@@ -437,11 +442,13 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
IERC20(token).safeTransfer(msg.sender, amount);
emit StakeWithdrawn(msg.sender, amount, stakeId);
return;
found = true;
break;
}
}
revert("Stake not found");
require(found, "Stake not found");
}
}
/// @notice Instantly buy out a portion of user's stake at configured percentage
@@ -454,6 +461,9 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
uint256 netStake = getNetStake(msg.sender);
require(amount <= netStake, "Insufficient net stake");
// Require minimum 25% of user's net stake
require(amount >= (netStake * 2500) / 10000, "Amount too low");
uint256 payoutAmount = (amount * instantBuyoutPercent) / 10000;
// Deduct amount from user's big stake