marketplace min and multiple withdrawStakes
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -415,33 +415,40 @@ 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 i = 0; i < userStakes.length; i++) {
|
||||
WithdrawStake storage stake = userStakes[i];
|
||||
if (stake.stakeId == stakeId && stake.amount > 0) {
|
||||
require(block.timestamp >= stake.unlockTime, "Stake locked");
|
||||
|
||||
uint256 amount = stake.amount;
|
||||
address token = stake.token;
|
||||
stake.amount = 0; // Mark as withdrawn
|
||||
|
||||
// Decrement withdraw vesting liabilities for non-BSC tokens
|
||||
if (token != BSC_TOKEN) {
|
||||
withdrawVestingLiabilities[token] -= amount;
|
||||
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];
|
||||
if (stake.stakeId == stakeId && stake.amount > 0) {
|
||||
require(block.timestamp >= stake.unlockTime, "Stake locked");
|
||||
|
||||
uint256 amount = stake.amount;
|
||||
address token = stake.token;
|
||||
stake.amount = 0; // Mark as withdrawn
|
||||
|
||||
// Decrement withdraw vesting liabilities for non-BSC tokens
|
||||
if (token != BSC_TOKEN) {
|
||||
withdrawVestingLiabilities[token] -= amount;
|
||||
}
|
||||
|
||||
// Transfer tokens to user based on the specified token
|
||||
IERC20(token).safeTransfer(msg.sender, amount);
|
||||
|
||||
emit StakeWithdrawn(msg.sender, amount, stakeId);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// Transfer tokens to user based on the specified token
|
||||
IERC20(token).safeTransfer(msg.sender, amount);
|
||||
|
||||
emit StakeWithdrawn(msg.sender, amount, stakeId);
|
||||
return;
|
||||
}
|
||||
|
||||
require(found, "Stake not found");
|
||||
}
|
||||
|
||||
revert("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
|
||||
|
||||
Reference in New Issue
Block a user