NetStake changes
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -96,11 +96,13 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
// Epoch-based staking variables
|
// Epoch-based staking variables
|
||||||
mapping(uint256 => Epoch) public epochs;
|
mapping(uint256 => Epoch) public epochs;
|
||||||
mapping(address => uint256) public userBigStake; // User's main stake amount
|
mapping(address => uint256) public userBigStake; // User's main stake amount
|
||||||
|
mapping(address => uint256) public userOriginalStake; // User's original stake amount (never changes)
|
||||||
mapping(address => uint256) public userLastClaimedEpoch; // Last epoch user claimed from
|
mapping(address => uint256) public userLastClaimedEpoch; // Last epoch user claimed from
|
||||||
mapping(address => WithdrawStake[]) public withdrawStakes; // User's withdrawable stakes
|
mapping(address => WithdrawStake[]) public withdrawStakes; // User's withdrawable stakes
|
||||||
uint256 public currentEpochId;
|
uint256 public currentEpochId;
|
||||||
uint256 public totalBigStakes; // Total liability (sum of all user stakes)
|
uint256 public totalBigStakes; // Total liability (sum of all user stakes)
|
||||||
uint256 public instantBuyoutPercent;// Percentage for instant buyout (e.g., 8000 = 80%)
|
uint256 public instantBuyoutPercent;// Percentage for instant buyout (e.g., 8000 = 80%)
|
||||||
|
uint256 public maxUnlockPercentage; // Maximum unlock percentage per epoch (e.g., 100 = 1%)
|
||||||
|
|
||||||
// Marketplace variables
|
// Marketplace variables
|
||||||
mapping(address => mapping(uint256 => SellStake)) public sellStakes; // seller => stakeId => SellStake
|
mapping(address => mapping(uint256 => SellStake)) public sellStakes; // seller => stakeId => SellStake
|
||||||
@@ -162,6 +164,7 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
totalBigStakes += 10000 * 1e18;
|
totalBigStakes += 10000 * 1e18;
|
||||||
|
|
||||||
unlockDelay = 60 * 60 * 36;
|
unlockDelay = 60 * 60 * 36;
|
||||||
|
maxUnlockPercentage = 100; // 1% maximum unlock per epoch
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ownership Management
|
// Ownership Management
|
||||||
@@ -187,6 +190,11 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
function updateUnlockDelay(uint256 _delay) external onlyOwner {
|
function updateUnlockDelay(uint256 _delay) external onlyOwner {
|
||||||
unlockDelay = _delay;
|
unlockDelay = _delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateMaxUnlockPercentage(uint256 _maxPercentage) external onlyOwner {
|
||||||
|
require(_maxPercentage > 0, "Max percentage must be greater than 0");
|
||||||
|
maxUnlockPercentage = _maxPercentage;
|
||||||
|
}
|
||||||
|
|
||||||
function withdrawFromVestingPool(address _token, uint256 _amount) external onlyOwner {
|
function withdrawFromVestingPool(address _token, uint256 _amount) external onlyOwner {
|
||||||
IERC20(_token).safeTransfer(msg.sender, _amount);
|
IERC20(_token).safeTransfer(msg.sender, _amount);
|
||||||
@@ -338,6 +346,9 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that unlock percentage doesn't exceed maximum
|
||||||
|
require(unlockPercentage <= maxUnlockPercentage, "Unlock percentage high");
|
||||||
|
|
||||||
// Create new epoch entry
|
// Create new epoch entry
|
||||||
epochs[currentEpochId] = Epoch({
|
epochs[currentEpochId] = Epoch({
|
||||||
estDaysRemaining: estDaysRemaining,
|
estDaysRemaining: estDaysRemaining,
|
||||||
@@ -354,7 +365,7 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
|
|
||||||
/// @notice Calculate total unclaimed funds for a user across all epochs since last claim
|
/// @notice Calculate total unclaimed funds for a user across all epochs since last claim
|
||||||
function calculateUnclaimedFunds(address user) public view returns (uint256 totalUnclaimed) {
|
function calculateUnclaimedFunds(address user) public view returns (uint256 totalUnclaimed) {
|
||||||
uint256 remainingStake = userBigStake[user];
|
uint256 remainingStake = getNetStake(user);
|
||||||
uint256 startEpoch = userLastClaimedEpoch[user];
|
uint256 startEpoch = userLastClaimedEpoch[user];
|
||||||
|
|
||||||
for (uint256 i = startEpoch; i < currentEpochId; i++) {
|
for (uint256 i = startEpoch; i < currentEpochId; i++) {
|
||||||
@@ -370,23 +381,24 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
/// @notice Get user's net stake (big stake minus unclaimed funds minus pending sell stakes)
|
/// @notice Get user's net stake (big stake minus unclaimed funds minus pending sell stakes)
|
||||||
function getNetStake(address user) public view returns (uint256) {
|
function getNetStake(address user) public view returns (uint256) {
|
||||||
uint256 bigStake = userBigStake[user];
|
uint256 bigStake = userBigStake[user];
|
||||||
uint256 unclaimed = calculateUnclaimedFunds(user);
|
uint256 committed = pendingSellStakes[user];
|
||||||
uint256 pending = pendingSellStakes[user];
|
|
||||||
uint256 committed = unclaimed + pending;
|
|
||||||
return bigStake > committed ? bigStake - committed : 0;
|
return bigStake > committed ? bigStake - committed : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice Get comprehensive user stake information
|
/// @notice Get comprehensive user stake information
|
||||||
function getUserStakeInfo(address user) external view returns (
|
function getUserStakeInfo(address user) external view returns (
|
||||||
uint256 netStake, // Current "active" stake amount
|
uint256 bigStake, // Current "active" stake amount
|
||||||
uint256 unclaimedFunds, // Available to claim
|
uint256 unclaimedFunds, // Available to claim
|
||||||
uint256 totalOriginalStake // Original big number (for reference)
|
uint256 netStake, // Available for new actions (minus pending sells)
|
||||||
|
uint256 originalStake // Original stake amount (never changes)
|
||||||
) {
|
) {
|
||||||
uint256 unclaimed = calculateUnclaimedFunds(user);
|
uint256 unclaimed = calculateUnclaimedFunds(user);
|
||||||
|
uint256 net = getNetStake(user);
|
||||||
return (
|
return (
|
||||||
userBigStake[user] - unclaimed, // Net stake
|
userBigStake[user],
|
||||||
unclaimed, // Unclaimed
|
unclaimed,
|
||||||
userBigStake[user] // Original
|
net,
|
||||||
|
userOriginalStake[user]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,6 +517,11 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
// Update total stakes accounting
|
// Update total stakes accounting
|
||||||
totalBigStakes = totalBigStakes - userBigStake[user] + amount;
|
totalBigStakes = totalBigStakes - userBigStake[user] + amount;
|
||||||
|
|
||||||
|
// Set original stake only if this is the first time (never changes after)
|
||||||
|
if (userOriginalStake[user] == 0) {
|
||||||
|
userOriginalStake[user] = amount;
|
||||||
|
}
|
||||||
|
|
||||||
// Set user's big stake
|
// Set user's big stake
|
||||||
userBigStake[user] = amount;
|
userBigStake[user] = amount;
|
||||||
|
|
||||||
@@ -732,8 +749,8 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
userBigStake[seller] -= value;
|
userBigStake[seller] -= value;
|
||||||
userBigStake[msg.sender] += buyerStake;
|
userBigStake[msg.sender] += buyerStake;
|
||||||
pendingSellStakes[seller] -= value;
|
pendingSellStakes[seller] -= value;
|
||||||
// Note: totalBigStakes decreases by protocolShare (value - buyerStake)
|
// Note: totalBigStakes decreases by protocolShare
|
||||||
totalBigStakes -= (value - buyerStake);
|
totalBigStakes -= protocolShare;
|
||||||
|
|
||||||
// Track marketplace sales for seller
|
// Track marketplace sales for seller
|
||||||
marketplace_sales[seller] += salePrice;
|
marketplace_sales[seller] += salePrice;
|
||||||
|
|||||||
Reference in New Issue
Block a user