Highest Ratio Change
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -114,6 +114,7 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
mapping(address => mapping(uint256 => uint256)) private sellStakeKeyIndex; // Track position in keys array
|
mapping(address => mapping(uint256 => uint256)) private sellStakeKeyIndex; // Track position in keys array
|
||||||
MarketplaceHistory[] public marketplaceHistory; // Complete history of all transactions
|
MarketplaceHistory[] public marketplaceHistory; // Complete history of all transactions
|
||||||
mapping(address => uint256) public totalClaimed; // Track total amount claimed and sent to withdrawStakes per user
|
mapping(address => uint256) public totalClaimed; // Track total amount claimed and sent to withdrawStakes per user
|
||||||
|
uint256 public highestRatio; // Track the highest TVL/liability ratio ever achieved (scaled by 10000)
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
event VestingClaimed(address indexed user, uint256 amount, uint256 bonus);
|
event VestingClaimed(address indexed user, uint256 amount, uint256 bonus);
|
||||||
@@ -196,6 +197,10 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
maxUnlockPercentage = _maxPercentage;
|
maxUnlockPercentage = _maxPercentage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateHighestRatio(uint256 _highestRatio) external onlyOwner {
|
||||||
|
highestRatio = _highestRatio;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
emit FundsWithdrawn(msg.sender, _token, _amount);
|
emit FundsWithdrawn(msg.sender, _token, _amount);
|
||||||
@@ -305,7 +310,7 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
uint256 lastTvl,
|
uint256 lastTvl,
|
||||||
uint256 lastLiability,
|
uint256 lastLiability,
|
||||||
uint256 paybackPercent
|
uint256 paybackPercent
|
||||||
) internal pure returns (uint256) {
|
) internal view returns (uint256) {
|
||||||
|
|
||||||
if (lastLiability == 0 || currentLiability == 0) {
|
if (lastLiability == 0 || currentLiability == 0) {
|
||||||
return 0; // Safety check
|
return 0; // Safety check
|
||||||
@@ -315,6 +320,11 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
uint256 currentRatio = (currentTvl * 10000) / currentLiability;
|
uint256 currentRatio = (currentTvl * 10000) / currentLiability;
|
||||||
uint256 lastRatio = (lastTvl * 10000) / lastLiability;
|
uint256 lastRatio = (lastTvl * 10000) / lastLiability;
|
||||||
|
|
||||||
|
// Check if current ratio is below the highest ratio ever achieved
|
||||||
|
if (currentRatio < highestRatio) {
|
||||||
|
return 0; // No unlock if we're below historical high
|
||||||
|
}
|
||||||
|
|
||||||
if (currentRatio <= lastRatio) {
|
if (currentRatio <= lastRatio) {
|
||||||
return 0; // No unlock if ratio didn't improve
|
return 0; // No unlock if ratio didn't improve
|
||||||
}
|
}
|
||||||
@@ -333,6 +343,14 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
function endEpoch(uint256 estDaysRemaining, uint256 currentTreasuryTvl, uint256 _paybackPercent, uint256 _currentLiability) external onlyOwner {
|
function endEpoch(uint256 estDaysRemaining, uint256 currentTreasuryTvl, uint256 _paybackPercent, uint256 _currentLiability) external onlyOwner {
|
||||||
uint256 unlockPercentage = 0;
|
uint256 unlockPercentage = 0;
|
||||||
|
|
||||||
|
// Calculate current ratio and update highest ratio if necessary
|
||||||
|
if (_currentLiability > 0) {
|
||||||
|
uint256 currentRatio = (currentTreasuryTvl * 10000) / _currentLiability;
|
||||||
|
if (currentRatio > highestRatio) {
|
||||||
|
highestRatio = currentRatio;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (currentEpochId > 0) {
|
if (currentEpochId > 0) {
|
||||||
// Get previous epoch data
|
// Get previous epoch data
|
||||||
Epoch storage lastEpoch = epochs[currentEpochId - 1];
|
Epoch storage lastEpoch = epochs[currentEpochId - 1];
|
||||||
@@ -353,7 +371,7 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
epochs[currentEpochId] = Epoch({
|
epochs[currentEpochId] = Epoch({
|
||||||
estDaysRemaining: estDaysRemaining,
|
estDaysRemaining: estDaysRemaining,
|
||||||
currentTreasuryTvl: currentTreasuryTvl,
|
currentTreasuryTvl: currentTreasuryTvl,
|
||||||
totalLiability: totalBigStakes,
|
totalLiability: _currentLiability,
|
||||||
paybackPercent: _paybackPercent,
|
paybackPercent: _paybackPercent,
|
||||||
unlockPercentage: unlockPercentage,
|
unlockPercentage: unlockPercentage,
|
||||||
timestamp: block.timestamp
|
timestamp: block.timestamp
|
||||||
@@ -1241,39 +1259,39 @@ contract CunaFinanceBsc is Initializable, ReentrancyGuardUpgradeable {
|
|||||||
return totalClaimed[user];
|
return totalClaimed[user];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice Search marketplace history for stakes where address was seller or buyer
|
// /// @notice Search marketplace history for stakes where address was seller or buyer
|
||||||
/// @param targetAddress The address to search for as seller or buyer
|
// /// @param targetAddress The address to search for as seller or buyer
|
||||||
/// @return Array of MarketplaceHistory structs where address was involved
|
// /// @return Array of MarketplaceHistory structs where address was involved
|
||||||
function searchMarketplaceHistory(address targetAddress) external view returns (MarketplaceHistory[] memory) {
|
// function searchMarketplaceHistory(address targetAddress) external view returns (MarketplaceHistory[] memory) {
|
||||||
require(targetAddress != address(0), "Invalid address");
|
// require(targetAddress != address(0), "Invalid address");
|
||||||
|
|
||||||
// Count matches first to size the result array properly
|
// // Count matches first to size the result array properly
|
||||||
uint256 matchCount = 0;
|
// uint256 matchCount = 0;
|
||||||
for (uint256 i = 0; i < marketplaceHistory.length; i++) {
|
// for (uint256 i = 0; i < marketplaceHistory.length; i++) {
|
||||||
if (marketplaceHistory[i].seller == targetAddress || marketplaceHistory[i].buyer == targetAddress) {
|
// if (marketplaceHistory[i].seller == targetAddress || marketplaceHistory[i].buyer == targetAddress) {
|
||||||
matchCount++;
|
// matchCount++;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Return empty array if no matches
|
// // Return empty array if no matches
|
||||||
if (matchCount == 0) {
|
// if (matchCount == 0) {
|
||||||
return new MarketplaceHistory[](0);
|
// return new MarketplaceHistory[](0);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Create result array with exact size needed
|
// // Create result array with exact size needed
|
||||||
MarketplaceHistory[] memory result = new MarketplaceHistory[](matchCount);
|
// MarketplaceHistory[] memory result = new MarketplaceHistory[](matchCount);
|
||||||
uint256 resultIndex = 0;
|
// uint256 resultIndex = 0;
|
||||||
|
|
||||||
// Populate result array
|
// // Populate result array
|
||||||
for (uint256 i = 0; i < marketplaceHistory.length; i++) {
|
// for (uint256 i = 0; i < marketplaceHistory.length; i++) {
|
||||||
if (marketplaceHistory[i].seller == targetAddress || marketplaceHistory[i].buyer == targetAddress) {
|
// if (marketplaceHistory[i].seller == targetAddress || marketplaceHistory[i].buyer == targetAddress) {
|
||||||
result[resultIndex] = marketplaceHistory[i];
|
// result[resultIndex] = marketplaceHistory[i];
|
||||||
resultIndex++;
|
// resultIndex++;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return result;
|
// return result;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// @notice Test function for upgrade verification
|
/// @notice Test function for upgrade verification
|
||||||
/// @return Returns a constant value to verify upgrade worked
|
/// @return Returns a constant value to verify upgrade worked
|
||||||
|
|||||||
Reference in New Issue
Block a user