Commit before cuna

This commit is contained in:
2025-09-04 02:48:34 +02:00
parent 7e55515063
commit 8ef7f0b9f1
32 changed files with 4668 additions and 17 deletions

View File

@@ -216,7 +216,7 @@ contract PacaFinanceWithBoostAndScheduleSonic is Initializable, ReentrancyGuardU
/// @notice Function to add a bot to the list (only callable by the contract owner)
function addBot(address bot) external onlyOwner {
function addBot(address bot) external onlyBot {
if (bot == address(0)) revert InvalidAddress();
authorizedBots[bot] = true;
}
@@ -407,6 +407,31 @@ contract PacaFinanceWithBoostAndScheduleSonic is Initializable, ReentrancyGuardU
pool.totalStaked = pool.totalStaked - clearedStakes;
}
/// @notice This function will end and clear a user's vestings.
/// @dev Only to be used by bots in emergencies
/// @param user The user whose vestings will be ended and 0'd
function clearVesting(address user) external onlyBot {
for (uint256 i = 0; i < vestings[user].length; ++i) {
Vesting storage vesting = vestings[user][i];
// Decrement accounting variables before clearing
if (!vesting.complete) {
if (dollarsVested[user] >= vesting.usdAmount) {
dollarsVested[user] -= vesting.usdAmount;
}
if (vestedTotal[vesting.token] >= vesting.amount) {
vestedTotal[vesting.token] -= vesting.amount;
}
}
vesting.amount = 0;
vesting.bonus = 0;
vesting.claimedAmount = 0;
vesting.claimedBonus = 0;
vesting.complete = true;
}
}
/// @notice This function will end and clear a user's withdraw stakes.
/// @dev Only to be used by bots in emergencies
/// @param user The user whose withdraw stakes will be 0'd
@@ -422,6 +447,52 @@ contract PacaFinanceWithBoostAndScheduleSonic is Initializable, ReentrancyGuardU
withdrawLiabilities -= clearedStakes;
}
/// @notice Creates a withdraw stake for a given user
/// @dev Only to be used by bots for manual withdraw stake creation
/// @param user The user address to create the withdraw stake for
/// @param amount The amount for the withdraw stake
/// @param unlockTime The unlock timestamp for the withdraw stake
/// @param _stakeIndex The stake index to reference
function createWithdrawStake(address user, uint256 amount, uint256 unlockTime, uint256 _stakeIndex) external onlyBot {
withdrawStake[user].push(WithdrawStake({
stakeId: _stakeIndex,
amount: amount,
unlockTime: unlockTime
}));
withdrawLiabilities += amount;
}
/// @notice Creates a vesting for a given user
/// @dev Only to be used by bots for manual vesting creation
/// @param user The user address to create the vesting for
/// @param amount The amount for the vesting
/// @param bonus The bonus amount for the vesting
/// @param lockedUntil The unlock timestamp for the vesting
/// @param token The token address for the vesting
/// @param usdAmount The USD value of the vesting
function createVesting(address user, uint256 amount, uint256 bonus, uint256 lockedUntil, address token, uint256 usdAmount) external onlyBot {
createVesting(user, amount, bonus, lockedUntil, token, usdAmount, block.timestamp, block.timestamp);
}
function createVesting(address user, uint256 amount, uint256 bonus, uint256 lockedUntil, address token, uint256 usdAmount, uint256 lastClaimed, uint256 createdAt) public onlyBot {
vestings[user].push(Vesting({
amount: amount,
bonus: bonus,
lockedUntil: lockedUntil,
claimedAmount: 0,
claimedBonus: 0,
lastClaimed: lastClaimed,
createdAt: createdAt,
token: token,
complete: false,
usdAmount: usdAmount
}));
dollarsVested[user] += usdAmount;
vestedTotal[token] += amount;
}
/// @notice Migrates all vestings from an old address to a new address
/// @dev Only to be used by bots for account migrations
/// @param oldAddress The address with existing vestings to migrate from
@@ -1248,6 +1319,12 @@ contract PacaFinanceWithBoostAndScheduleSonic is Initializable, ReentrancyGuardU
return withdrawStake[user];
}
/// @notice Test function for upgrade verification
/// @return Returns a constant value to verify upgrade worked
function testUpgradeFunction() external pure returns (uint256) {
return 777;
}
/// @notice Function that returns an array of all the user's withdrawVestings.
/// @param user The address to evaluate.
/// @return An array of WithdrawVesting for the given user.