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
|
/// @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];
|
WithdrawStake[] storage userStakes = withdrawStakes[msg.sender];
|
||||||
require(userStakes.length > 0, "No stakes available");
|
require(userStakes.length > 0, "No stakes available");
|
||||||
|
require(stakeIds.length > 0, "No stake IDs provided");
|
||||||
|
|
||||||
for (uint256 i = 0; i < userStakes.length; i++) {
|
for (uint256 j = 0; j < stakeIds.length; j++) {
|
||||||
WithdrawStake storage stake = userStakes[i];
|
uint256 stakeId = stakeIds[j];
|
||||||
if (stake.stakeId == stakeId && stake.amount > 0) {
|
bool found = false;
|
||||||
require(block.timestamp >= stake.unlockTime, "Stake locked");
|
|
||||||
|
|
||||||
uint256 amount = stake.amount;
|
for (uint256 i = 0; i < userStakes.length; i++) {
|
||||||
address token = stake.token;
|
WithdrawStake storage stake = userStakes[i];
|
||||||
stake.amount = 0; // Mark as withdrawn
|
if (stake.stakeId == stakeId && stake.amount > 0) {
|
||||||
|
require(block.timestamp >= stake.unlockTime, "Stake locked");
|
||||||
|
|
||||||
// Decrement withdraw vesting liabilities for non-BSC tokens
|
uint256 amount = stake.amount;
|
||||||
if (token != BSC_TOKEN) {
|
address token = stake.token;
|
||||||
withdrawVestingLiabilities[token] -= amount;
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
revert("Stake not found");
|
require(found, "Stake not found");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice Instantly buy out a portion of user's stake at configured percentage
|
/// @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);
|
uint256 netStake = getNetStake(msg.sender);
|
||||||
require(amount <= netStake, "Insufficient net stake");
|
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;
|
uint256 payoutAmount = (amount * instantBuyoutPercent) / 10000;
|
||||||
|
|
||||||
// Deduct amount from user's big stake
|
// Deduct amount from user's big stake
|
||||||
|
|||||||
Reference in New Issue
Block a user