diff --git a/contracts/EscrowMigrator.sol b/contracts/EscrowMigrator.sol index 943e51b1d..613a00e2b 100644 --- a/contracts/EscrowMigrator.sol +++ b/contracts/EscrowMigrator.sol @@ -33,6 +33,7 @@ import {IStakingRewardsIntegrator} from "./interfaces/IStakingRewardsIntegrator. /// @title KWENTA Escrow Migrator /// Used to migrate escrow entries from RewardEscrowV1 to RewardEscrowV2 /// @author tommyrharper (tom@zkconsulting.xyz) +/// @author Flocqst (florian@kwenta.io) contract EscrowMigrator is IEscrowMigrator, Ownable2StepUpgradeable, @@ -410,7 +411,6 @@ contract EscrowMigrator is _payForMigration(_account); uint256 migratedEscrow; - uint256 cooldown = stakingRewardsV2.cooldownPeriod(); mapping(uint256 => VestingEntry) storage userEntries = registeredVestingSchedules[_account]; for (uint256 i = 0; i < _entryIDs.length; i++) { @@ -432,15 +432,6 @@ contract EscrowMigrator is registeredEntry.migrated = true; migratedEscrow += originalEscrowAmount; - /// @dev it essential for security that the duration is not less than the cooldown period, - /// otherwise the user could do a governance attack by bypassing the unstaking cooldown lock - /// by migrating their escrow then staking, voting, and vesting immediately - if (duration < cooldown) { - uint256 timeCreated = endTime - duration; - duration = cooldown; - endTime = timeCreated + cooldown; - } - IRewardEscrowV2.VestingEntry memory entry = IRewardEscrowV2.VestingEntry({ escrowAmount: originalEscrowAmount, duration: duration, diff --git a/contracts/RewardEscrowV2.sol b/contracts/RewardEscrowV2.sol index f2e02bd68..8387ca166 100644 --- a/contracts/RewardEscrowV2.sol +++ b/contracts/RewardEscrowV2.sol @@ -19,7 +19,7 @@ import {IEscrowMigrator} from "./interfaces/IEscrowMigrator.sol"; /// @title KWENTA Reward Escrow V2 /// @author Originally inspired by SYNTHETIX RewardEscrow /// @author Kwenta's RewardEscrow V1 by JaredBorders (jaredborders@proton.me), JChiaramonte7 (jeremy@bytecode.llc) -/// @author RewardEscrowV2 by tommyrharper (tom@zkconsulting.xyz) +/// @author RewardEscrowV2 by tommyrharper (tom@zkconsulting.xyz), Flocqst (florian@kwenta.io) /// @notice Updated version of Synthetix's RewardEscrow with new features specific to Kwenta contract RewardEscrowV2 is IRewardEscrowV2, @@ -379,7 +379,7 @@ contract RewardEscrowV2 is unchecked { amountToUnstake = totalWithFee - unstakedEscrow; } - stakingRewards.unstakeEscrowSkipCooldown(msg.sender, amountToUnstake); + stakingRewards.unstakeEscrowAdmin(msg.sender, amountToUnstake); } // update balances @@ -432,8 +432,7 @@ contract RewardEscrowV2 is if (_earlyVestingFee > MAXIMUM_EARLY_VESTING_FEE) revert EarlyVestingFeeTooHigh(); if (_earlyVestingFee < MINIMUM_EARLY_VESTING_FEE) revert EarlyVestingFeeTooLow(); if (_deposit == 0) revert ZeroAmount(); - uint256 minimumDuration = stakingRewards.cooldownPeriod(); - if (_duration < minimumDuration || _duration > MAX_DURATION) revert InvalidDuration(); + if (_duration == 0 || _duration > MAX_DURATION) revert InvalidDuration(); /// @dev this will revert if the kwenta token transfer fails kwenta.transferFrom(msg.sender, address(this), _deposit); diff --git a/contracts/StakingRewardsV2.sol b/contracts/StakingRewardsV2.sol index 9a2d712c1..14c54832b 100644 --- a/contracts/StakingRewardsV2.sol +++ b/contracts/StakingRewardsV2.sol @@ -15,7 +15,7 @@ import {IRewardEscrowV2} from "./interfaces/IRewardEscrowV2.sol"; /// @title KWENTA Staking Rewards V2 /// @author Originally inspired by SYNTHETIX StakingRewards /// @author Kwenta's StakingRewards V1 by JaredBorders (jaredborders@proton.me), JChiaramonte7 (jeremy@bytecode.llc) -/// @author StakingRewardsV2 (this) by tommyrharper (tom@zkconsulting.xyz) +/// @author StakingRewardsV2 (this) by tommyrharper (tom@zkconsulting.xyz), Flocqst (florian@kwenta.io) /// @notice Updated version of Synthetix's StakingRewards with new features specific to Kwenta contract StakingRewardsV2 is IStakingRewardsV2, @@ -27,12 +27,6 @@ contract StakingRewardsV2 is CONSTANTS/IMMUTABLES ///////////////////////////////////////////////////////////////*/ - /// @notice minimum time length of the unstaking cooldown period - uint256 public constant MIN_COOLDOWN_PERIOD = 1 weeks; - - /// @notice maximum time length of the unstaking cooldown period - uint256 public constant MAX_COOLDOWN_PERIOD = 52 weeks; - /// @notice Contract for KWENTA ERC20 token - used for BOTH staking and rewards /// @custom:oz-upgrades-unsafe-allow state-variable-immutable IKwenta public immutable kwenta; @@ -81,9 +75,6 @@ contract StakingRewardsV2 is /// @notice summation of rewardRate divided by total staked tokens uint256 public rewardPerTokenStored; - /// @inheritdoc IStakingRewardsV2 - uint256 public cooldownPeriod; - /// @notice represents the rewardPerToken /// value the last time the staker calculated earned() rewards mapping(address => uint256) public userRewardPerTokenPaid; @@ -136,17 +127,6 @@ contract StakingRewardsV2 is if (msg.sender != address(rewardsNotifier)) revert OnlyRewardsNotifier(); } - /// @notice only allow execution after the unstaking cooldown period has elapsed - modifier afterCooldown(address _account) { - _afterCooldown(_account); - _; - } - - function _afterCooldown(address _account) internal view { - uint256 canUnstakeAt = userLastStakeTime[_account] + cooldownPeriod; - if (canUnstakeAt > block.timestamp) revert MustWaitForUnlock(canUnstakeAt); - } - /*/////////////////////////////////////////////////////////////// CONSTRUCTOR / INITIALIZER ///////////////////////////////////////////////////////////////*/ @@ -191,7 +171,6 @@ contract StakingRewardsV2 is // define values rewardsDuration = 1 weeks; - cooldownPeriod = 2 weeks; } /*/////////////////////////////////////////////////////////////// @@ -239,28 +218,30 @@ contract StakingRewardsV2 is ///////////////////////////////////////////////////////////////*/ /// @inheritdoc IStakingRewardsV2 - function stake(uint256 _amount) external whenNotPaused updateReward(msg.sender) { + function stake(uint256 _amount) external { + _stake(msg.sender, _amount); + + // transfer token to this contract from the caller + kwenta.transferFrom(msg.sender, address(this), _amount); + } + + function _stake(address _account, uint256 _amount) + internal + whenNotPaused + updateReward(_account) + { if (_amount == 0) revert AmountZero(); // update state - userLastStakeTime[msg.sender] = block.timestamp; _addTotalSupplyCheckpoint(totalSupply() + _amount); - _addBalancesCheckpoint(msg.sender, balanceOf(msg.sender) + _amount); - - // emit staking event and index msg.sender - emit Staked(msg.sender, _amount); + _addBalancesCheckpoint(_account, balanceOf(_account) + _amount); - // transfer token to this contract from the caller - kwenta.transferFrom(msg.sender, address(this), _amount); + // emit staking event and index _account + emit Staked(_account, _amount); } /// @inheritdoc IStakingRewardsV2 - function unstake(uint256 _amount) - public - whenNotPaused - updateReward(msg.sender) - afterCooldown(msg.sender) - { + function unstake(uint256 _amount) public whenNotPaused updateReward(msg.sender) { if (_amount == 0) revert AmountZero(); uint256 nonEscrowedBalance = nonEscrowedBalanceOf(msg.sender); if (_amount > nonEscrowedBalance) revert InsufficientBalance(nonEscrowedBalance); @@ -291,7 +272,6 @@ contract StakingRewardsV2 is if (_amount > unstakedEscrow) revert InsufficientUnstakedEscrow(unstakedEscrow); // update state - userLastStakeTime[_account] = block.timestamp; _addBalancesCheckpoint(_account, balanceOf(_account) + _amount); _addEscrowedBalancesCheckpoint(_account, escrowedBalanceOf(_account) + _amount); @@ -304,15 +284,12 @@ contract StakingRewardsV2 is } /// @inheritdoc IStakingRewardsV2 - function unstakeEscrow(uint256 _amount) external afterCooldown(msg.sender) { + function unstakeEscrow(uint256 _amount) external { _unstakeEscrow(msg.sender, _amount); } /// @inheritdoc IStakingRewardsV2 - function unstakeEscrowSkipCooldown(address _account, uint256 _amount) - external - onlyRewardEscrow - { + function unstakeEscrowAdmin(address _account, uint256 _amount) external onlyRewardEscrow { _unstakeEscrow(_account, _amount); } @@ -361,31 +338,44 @@ contract StakingRewardsV2 is whenNotPaused updateReward(_account) { - uint256 reward = rewards[_account]; - if (reward > 0) { + _processReward(_account, _to, true); + } + + /// @notice Process KWENTA and USDC rewards + /// @dev transferKwenta is set to false when compounding KWENTA rewards + /// @param _account The address of the account to process rewards for + /// @param _to The address to transfer rewards to + /// @param transferKwenta Boolean flag to determine if Kwenta should be transferred + /// @return kwentaReward The amount of Kwenta reward processed + function _processReward(address _account, address _to, bool transferKwenta) + internal + updateReward(_account) + returns (uint256 kwentaReward) + { + // Process Kwenta reward + kwentaReward = rewards[_account]; + if (kwentaReward > 0) { // update state (first) rewards[_account] = 0; // emit reward claimed event and index account - emit RewardPaid(_account, reward); + emit RewardPaid(_account, kwentaReward); - // transfer token from this contract to the rewardEscrow - // and create a vesting entry at the _to address - kwenta.transfer(address(rewardEscrow), reward); - rewardEscrow.appendVestingEntry(_to, reward); + if (transferKwenta) { + kwenta.transfer(_to, kwentaReward); + } } - uint256 rewardUSDC = rewardsUSDC[_account] / PRECISION; - if (rewardUSDC > 0) { + // Process USDC reward + uint256 usdcReward = rewardsUSDC[_account] / PRECISION; + if (usdcReward > 0) { // update state (first) rewardsUSDC[_account] = 0; // emit reward claimed event and index account - emit RewardPaidUSDC(_account, rewardUSDC); + emit RewardPaidUSDC(_account, usdcReward); - // transfer token from this contract to the account - // as newly issued rewards from inflation are now issued as non-escrowed - usdc.transfer(_to, rewardUSDC); + usdc.transfer(_to, usdcReward); } } @@ -397,8 +387,8 @@ contract StakingRewardsV2 is /// @dev internal helper to compound for a given account /// @param _account the account to compound for function _compound(address _account) internal { - _getReward(_account); - _stakeEscrow(_account, unstakedEscrowedBalanceOf(_account)); + uint256 reward = _processReward(_account, _account, false); + _stake(_account, reward); } /*/////////////////////////////////////////////////////////////// @@ -688,17 +678,6 @@ contract StakingRewardsV2 is emit RewardsDurationUpdated(rewardsDuration); } - /// @inheritdoc IStakingRewardsV2 - function setCooldownPeriod(uint256 _cooldownPeriod) external onlyOwner { - if (_cooldownPeriod < MIN_COOLDOWN_PERIOD) revert CooldownPeriodTooLow(MIN_COOLDOWN_PERIOD); - if (_cooldownPeriod > MAX_COOLDOWN_PERIOD) { - revert CooldownPeriodTooHigh(MAX_COOLDOWN_PERIOD); - } - - cooldownPeriod = _cooldownPeriod; - emit CooldownPeriodUpdated(cooldownPeriod); - } - /*/////////////////////////////////////////////////////////////// PAUSABLE ///////////////////////////////////////////////////////////////*/ diff --git a/contracts/interfaces/IStakingRewardsV2.sol b/contracts/interfaces/IStakingRewardsV2.sol index 79f3bb1df..34cf0f49c 100644 --- a/contracts/interfaces/IStakingRewardsV2.sol +++ b/contracts/interfaces/IStakingRewardsV2.sol @@ -59,10 +59,7 @@ interface IStakingRewardsV2 { /// @param _account: address to check /// @return amount of tokens escrowed but not staked function unstakedEscrowedBalanceOf(address _account) external view returns (uint256); - - /// @notice the period of time a user has to wait after staking to unstake - function cooldownPeriod() external view returns (uint256); - + // rewards /// @notice calculate the total rewards for one duration based on the current rate @@ -158,11 +155,11 @@ interface IStakingRewardsV2 { /// @dev updateReward() called prior to function logic function unstakeEscrow(uint256 _amount) external; - /// @notice unstake escrowed token skipping the cooldown wait period + /// @notice unstake escrowed token on behalf of another account /// @param _account: address of account to unstake from /// @param _amount: amount to unstake /// @dev this function is used to allow tokens to be vested at any time by RewardEscrowV2 - function unstakeEscrowSkipCooldown(address _account, uint256 _amount) external; + function unstakeEscrowAdmin(address _account, uint256 _amount) external; /// @notice unstake all available staked non-escrowed tokens and /// claim any rewards @@ -211,10 +208,6 @@ interface IStakingRewardsV2 { /// @param _rewardsDuration: denoted in seconds function setRewardsDuration(uint256 _rewardsDuration) external; - /// @notice set unstaking cooldown period - /// @param _cooldownPeriod: denoted in seconds - function setCooldownPeriod(uint256 _cooldownPeriod) external; - // pausable /// @dev Triggers stopped state @@ -279,10 +272,6 @@ interface IStakingRewardsV2 { /// @param amount: amount of token recovered event Recovered(address token, uint256 amount); - /// @notice emitted when the unstaking cooldown period is updated - /// @param cooldownPeriod: the new unstaking cooldown period - event CooldownPeriodUpdated(uint256 cooldownPeriod); - /// @notice emitted when an operator is approved /// @param owner: owner of tokens /// @param operator: address of operator @@ -322,21 +311,9 @@ interface IStakingRewardsV2 { /// @notice recovering the usdc reward token is not allowed error CannotRecoverRewardToken(); - /// @notice error when user tries unstake during the cooldown period - /// @param canUnstakeAt timestamp when user can unstake - error MustWaitForUnlock(uint256 canUnstakeAt); - /// @notice error when trying to set a rewards duration that is too short error RewardsDurationCannotBeZero(); - /// @notice error when trying to set a cooldown period below the minimum - /// @param minCooldownPeriod minimum cooldown period - error CooldownPeriodTooLow(uint256 minCooldownPeriod); - - /// @notice error when trying to set a cooldown period above the maximum - /// @param maxCooldownPeriod maximum cooldown period - error CooldownPeriodTooHigh(uint256 maxCooldownPeriod); - /// @notice the caller is not approved to take this action error NotApproved(); diff --git a/test/foundry/integration/escrow.migrator.fork.t.sol b/test/foundry/integration/escrow.migrator.fork.t.sol index 7c9609765..ed1317538 100644 --- a/test/foundry/integration/escrow.migrator.fork.t.sol +++ b/test/foundry/integration/escrow.migrator.fork.t.sol @@ -794,26 +794,7 @@ contract StakingV2MigrationForkTests is EscrowMigratorTestHelpers { // check final state - user2 didn't manage to migrate any entries checkStateAfterStepThree(user1, 0, 0); } - - function test_Cannot_Bypass_Unstaking_Cooldown_Lock() public { - // this is the malicious entry - the duration is set to 1 - createRewardEscrowEntryV1(user1, 50 ether, 1); - - (uint256[] memory _entryIDs, uint256 numVestingEntries,) = claimAndFullyMigrate(user1); - checkStateAfterStepThree(user1, _entryIDs); - - // specifically - uint256[] memory migratedEntryIDs = - rewardEscrowV2.getAccountVestingEntryIDs(user1, numVestingEntries - 2, 1); - uint256 maliciousEntryID = migratedEntryIDs[0]; - (uint256 endTime, uint256 escrowAmount, uint256 duration, uint256 earlyVestingFee) = - rewardEscrowV2.getVestingEntry(maliciousEntryID); - assertEq(endTime, block.timestamp + stakingRewardsV2.cooldownPeriod()); - assertEq(escrowAmount, 50 ether); - assertEq(duration, stakingRewardsV2.cooldownPeriod()); - assertEq(earlyVestingFee, 90); - } - + function test_Cannot_Migrate_In_Non_Initiated_State() public { (uint256[] memory _entryIDs,) = claimAndCheckInitialState(user1); diff --git a/test/foundry/integration/stakingV2.migration.fork.t.sol b/test/foundry/integration/stakingV2.migration.fork.t.sol index 4a829d74b..7afda8c10 100644 --- a/test/foundry/integration/stakingV2.migration.fork.t.sol +++ b/test/foundry/integration/stakingV2.migration.fork.t.sol @@ -103,8 +103,11 @@ contract StakingV2MigrationForkTests is StakingTestHelpers { // get rewards getStakingRewardsV2(user1); + // assert v2 rewards have been earned + assertGt(kwenta.balanceOf(user1), 0); + // stake the rewards - stakeAllUnstakedEscrowV2(user1); + stakeFundsV2(user1, kwenta.balanceOf(user1)); // check StakingRewardsV1 balance unchanged assertEq(stakingRewardsV1.nonEscrowedBalanceOf(user1), 0); @@ -117,8 +120,6 @@ contract StakingV2MigrationForkTests is StakingTestHelpers { uint256 user1EscrowStakedV2 = stakingRewardsV2.escrowedBalanceOf(user1); uint256 user1NonEscrowedStakeV2 = stakingRewardsV2.nonEscrowedBalanceOf(user1); - // assert v2 rewards have been earned - assertGt(rewardEscrowV2.escrowedBalanceOf(user1), 0); // v2 staked balance is equal to escrowed + non-escrowed balance assertEq(stakingRewardsV2.balanceOf(user1), user1EscrowStakedV2 + user1NonEscrowedStakeV2); // v2 reward escrow balance is equal to escrow staked balance diff --git a/test/foundry/integration/stakingV2.migration.t.sol b/test/foundry/integration/stakingV2.migration.t.sol index 224a595fa..66b01ebc6 100644 --- a/test/foundry/integration/stakingV2.migration.t.sol +++ b/test/foundry/integration/stakingV2.migration.t.sol @@ -98,15 +98,25 @@ contract StakingV2MigrationTests is StakingTestHelpers { warpAndMint(2 weeks); warpAndMint(2 weeks); + // checks everything is staked + assertEq(kwenta.balanceOf(user1), 0); + assertEq(kwenta.balanceOf(user2), 0); + assertEq(kwenta.balanceOf(user3), 0); + // get rewards getStakingRewardsV2(user1); getStakingRewardsV2(user2); getStakingRewardsV2(user3); + // assert v2 rewards have been earned + assertGt(kwenta.balanceOf(user1), 0); + assertGt(kwenta.balanceOf(user2), 0); + assertGt(kwenta.balanceOf(user3), 0); + // stake the rewards - stakeAllUnstakedEscrowV2(user1); - stakeAllUnstakedEscrowV2(user2); - stakeAllUnstakedEscrowV2(user3); + stakeFundsV2(user1, kwenta.balanceOf(user1)); + stakeFundsV2(user2, kwenta.balanceOf(user2)); + stakeFundsV2(user3, kwenta.balanceOf(user3)); // check StakingRewardsV1 balance unchanged assertEq(stakingRewardsV1.nonEscrowedBalanceOf(user1), 0); @@ -135,11 +145,6 @@ contract StakingV2MigrationTests is StakingTestHelpers { user2NonEscrowedStakeV2 = stakingRewardsV2.nonEscrowedBalanceOf(user2); user3NonEscrowedStakeV2 = stakingRewardsV2.nonEscrowedBalanceOf(user3); - // assert v2 rewards have been earned - assertGt(rewardEscrowV2.escrowedBalanceOf(user1), 0); - assertGt(rewardEscrowV2.escrowedBalanceOf(user2), 0); - assertGt(rewardEscrowV2.escrowedBalanceOf(user3), 0); - // v2 staked balance is equal to escrowed + non-escrowed balance assertEq(stakingRewardsV2.balanceOf(user1), user1EscrowStakedV2 + user1NonEscrowedStakeV2); assertEq(stakingRewardsV2.balanceOf(user2), user2EscrowStakedV2 + user2NonEscrowedStakeV2); @@ -243,8 +248,11 @@ contract StakingV2MigrationTests is StakingTestHelpers { // get rewards getStakingRewardsV2(stakers[i]); + // assert v2 rewards have been earned + assertGt(kwenta.balanceOf(stakers[i]), 0); + // stake the rewards - stakeAllUnstakedEscrowV2(stakers[i]); + stakeFundsV2(stakers[i], kwenta.balanceOf(stakers[i])); } // check StakingRewardsV1 balance unchanged @@ -264,9 +272,6 @@ contract StakingV2MigrationTests is StakingTestHelpers { uint256 userEscrowStakedV2 = stakingRewardsV2.escrowedBalanceOf(stakers[i]); uint256 userNonEscrowedStakeV2 = stakingRewardsV2.nonEscrowedBalanceOf(stakers[i]); - // assert v2 rewards have been earned - assertGt(rewardEscrowV2.escrowedBalanceOf(stakers[i]), 0); - // v2 staked balance is equal to escrowed + non-escrowed balance assertEq( stakingRewardsV2.balanceOf(stakers[i]), userEscrowStakedV2 + userNonEscrowedStakeV2 diff --git a/test/foundry/integration/stakingV2.upgrade.t.sol b/test/foundry/integration/stakingV2.upgrade.t.sol index e80a9599b..00e315b80 100644 --- a/test/foundry/integration/stakingV2.upgrade.t.sol +++ b/test/foundry/integration/stakingV2.upgrade.t.sol @@ -232,14 +232,16 @@ contract StakingV2UpgradeTests is DefaultStakingV2Setup { // claim the rewards getStakingRewardsV2(user1); assertEq(1 ether, stakingRewardsV2.balanceOf(user1)); - assertEq(2, rewardEscrowV2.balanceOf(user1)); - assertEq(1 ether + 1 weeks, rewardEscrowV2.escrowedBalanceOf(user1)); - assertEq(1 ether + 1 weeks, rewardEscrowV2.unstakedEscrowedBalanceOf(user1)); + assertEq(1 weeks, kwenta.balanceOf(user1)); + assertEq(1, rewardEscrowV2.balanceOf(user1)); + assertEq(1 ether, rewardEscrowV2.escrowedBalanceOf(user1)); + assertEq(1 ether, rewardEscrowV2.unstakedEscrowedBalanceOf(user1)); // stake the rewards stakeAllUnstakedEscrowV2(user1); + stakeFundsV2(user1, 1 weeks); assertEq(2 ether + 1 weeks, stakingRewardsV2.balanceOf(user1)); - assertEq(1 ether + 1 weeks, stakingRewardsV2.escrowedBalanceOf(user1)); + assertEq(1 ether, stakingRewardsV2.escrowedBalanceOf(user1)); assertEq(0, rewardEscrowV2.unstakedEscrowedBalanceOf(user1)); } diff --git a/test/foundry/unit/RewardEscrowV2/RewardEscrowV2.t.sol b/test/foundry/unit/RewardEscrowV2/RewardEscrowV2.t.sol index a5996da23..65b4b3c4b 100644 --- a/test/foundry/unit/RewardEscrowV2/RewardEscrowV2.t.sol +++ b/test/foundry/unit/RewardEscrowV2/RewardEscrowV2.t.sol @@ -263,24 +263,12 @@ contract RewardEscrowV2Tests is DefaultStakingV2Setup { rewardEscrowV2.createEscrowEntry(address(this), 0, 52 weeks, 90); } - function test_createEscrowEntry_Should_Not_Append_Entries_With_Short_Duration() public { - uint256 duration = stakingRewardsV2.cooldownPeriod(); - - vm.prank(treasury); - kwenta.approve(address(rewardEscrowV2), TEST_VALUE); - vm.prank(treasury); - vm.expectRevert(IRewardEscrowV2.InvalidDuration.selector); - rewardEscrowV2.createEscrowEntry(address(this), TEST_VALUE, duration - 1, 90); - } - function test_createEscrowEntry_Should_Not_Append_Entries_With_Bad_Duration_Fuzz( uint40 duration ) public { - uint256 cooldownPeriod = stakingRewardsV2.cooldownPeriod(); - vm.prank(treasury); kwenta.approve(address(rewardEscrowV2), TEST_VALUE); - if (duration < cooldownPeriod || duration > rewardEscrowV2.MAX_DURATION()) { + if (duration == 0 || duration > rewardEscrowV2.MAX_DURATION()) { vm.expectRevert(IRewardEscrowV2.InvalidDuration.selector); } vm.prank(treasury); diff --git a/test/foundry/unit/RewardEscrowV2/RewardEscrowV2Transferability.t.sol b/test/foundry/unit/RewardEscrowV2/RewardEscrowV2Transferability.t.sol index 67ac5ddb3..8b5098d3e 100644 --- a/test/foundry/unit/RewardEscrowV2/RewardEscrowV2Transferability.t.sol +++ b/test/foundry/unit/RewardEscrowV2/RewardEscrowV2Transferability.t.sol @@ -41,7 +41,7 @@ contract RewardEscrowV2TransferabilityTests is DefaultStakingV2Setup { function test_Cannot_Steal_Other_Users_Entries_Fuzz(uint32 amount, uint24 duration) public { vm.assume(amount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); // create the escrow entry createRewardEscrowEntryV2(user1, amount, duration); @@ -61,7 +61,7 @@ contract RewardEscrowV2TransferabilityTests is DefaultStakingV2Setup { uint24 duration ) public { vm.assume(amount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); // create the escrow entry createRewardEscrowEntryV2(user1, amount, duration); @@ -95,7 +95,7 @@ contract RewardEscrowV2TransferabilityTests is DefaultStakingV2Setup { public { vm.assume(amount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); // create the escrow entry createRewardEscrowEntryV2(user1, amount, duration); @@ -241,7 +241,7 @@ contract RewardEscrowV2TransferabilityTests is DefaultStakingV2Setup { uint8 numberOfEntries ) public { vm.assume(escrowAmount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); vm.assume(numberOfEntries > 0); (uint256 totalEscrowedAmount, uint256 user1EntryID) = @@ -285,7 +285,7 @@ contract RewardEscrowV2TransferabilityTests is DefaultStakingV2Setup { ) public { vm.assume(escrowAmount > 0); vm.assume(stakedAmount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); vm.assume(escrowAmount >= stakedAmount); // create the escrow entry @@ -379,7 +379,7 @@ contract RewardEscrowV2TransferabilityTests is DefaultStakingV2Setup { uint8 numberOfEntries ) public { vm.assume(escrowAmount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); vm.assume(numberOfEntries > 0); (uint256 totalEscrowedAmount, uint256 user1EntryID) = @@ -423,7 +423,7 @@ contract RewardEscrowV2TransferabilityTests is DefaultStakingV2Setup { ) public { vm.assume(escrowAmount > 0); vm.assume(stakedAmount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); vm.assume(escrowAmount >= stakedAmount); // create the escrow entry @@ -520,7 +520,7 @@ contract RewardEscrowV2TransferabilityTests is DefaultStakingV2Setup { uint8 numberOfEntries ) public { vm.assume(escrowAmount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); vm.assume(numberOfEntries > 0); uint256 startingEntryToTransferIndex = @@ -582,7 +582,7 @@ contract RewardEscrowV2TransferabilityTests is DefaultStakingV2Setup { uint8 numberOfEntries ) public { vm.assume(escrowAmount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); vm.assume(numberOfEntries > 0); // create the escrow entry @@ -673,7 +673,7 @@ contract RewardEscrowV2TransferabilityTests is DefaultStakingV2Setup { vm.assume(escrowAmount > 0); vm.assume(stakedAmount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); vm.assume(numberOfEntries > 0); vm.assume(escrowAmount * numberOfEntries >= stakedAmount); @@ -746,7 +746,7 @@ contract RewardEscrowV2TransferabilityTests is DefaultStakingV2Setup { uint8 numberOfEntries ) public { vm.assume(escrowAmount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); vm.assume(numberOfEntries > 0); // create the escrow entries @@ -783,7 +783,7 @@ contract RewardEscrowV2TransferabilityTests is DefaultStakingV2Setup { uint8 numberOfEntries ) public { vm.assume(escrowAmount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); vm.assume(numberOfEntries > 0); // create the escrow entries diff --git a/test/foundry/unit/RewardEscrowV2/RewardEscrowV2VestingChanges.t.sol b/test/foundry/unit/RewardEscrowV2/RewardEscrowV2VestingChanges.t.sol index 160600090..1e0615895 100644 --- a/test/foundry/unit/RewardEscrowV2/RewardEscrowV2VestingChanges.t.sol +++ b/test/foundry/unit/RewardEscrowV2/RewardEscrowV2VestingChanges.t.sol @@ -48,7 +48,7 @@ contract RewardEscrowV2VestingChangesTests is DefaultStakingV2Setup { uint8 earlyVestingFee ) public { vm.assume(escrowAmount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); vm.assume(earlyVestingFee <= 100); vm.assume(earlyVestingFee > rewardEscrowV2.MINIMUM_EARLY_VESTING_FEE()); @@ -116,7 +116,7 @@ contract RewardEscrowV2VestingChangesTests is DefaultStakingV2Setup { uint8 earlyVestingFee = _earlyVestingFee; vm.assume(escrowAmount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); vm.assume(earlyVestingFee <= 100); vm.assume(earlyVestingFee > rewardEscrowV2.MINIMUM_EARLY_VESTING_FEE()); @@ -201,7 +201,7 @@ contract RewardEscrowV2VestingChangesTests is DefaultStakingV2Setup { vm.assume(escrowAmount > 0); vm.assume(stakingAmount > 0); vm.assume(stakingAmount <= escrowAmount); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); vm.assume(earlyVestingFee <= 100); vm.assume(earlyVestingFee > rewardEscrowV2.MINIMUM_EARLY_VESTING_FEE()); diff --git a/test/foundry/unit/StakingRewardsV2/StakingRewardsV2.t.sol b/test/foundry/unit/StakingRewardsV2/StakingRewardsV2.t.sol index 8e5a665ea..e98d803a8 100644 --- a/test/foundry/unit/StakingRewardsV2/StakingRewardsV2.t.sol +++ b/test/foundry/unit/StakingRewardsV2/StakingRewardsV2.t.sol @@ -72,21 +72,16 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { stakingRewardsV2.recoverERC20(address(kwenta), 0); } - function test_Only_RewardEscrowCan_Call_unstakeEscrowSkipCooldown() public { + function test_Only_RewardEscrow_Can_Call_unstakeEscrowAdmin() public { stakeEscrowedFundsV2(address(this), TEST_VALUE); - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); + vm.warp(block.timestamp + 2 weeks); vm.expectRevert(IStakingRewardsV2.OnlyRewardEscrow.selector); - stakingRewardsV2.unstakeEscrowSkipCooldown(address(this), TEST_VALUE); + stakingRewardsV2.unstakeEscrowAdmin(address(this), TEST_VALUE); } function test_Cannot_unstakeEscrow_Invalid_Amount() public { - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - vm.expectRevert(abi.encodeWithSelector(IStakingRewardsV2.InsufficientBalance.selector, 0)); unstakeEscrowedFundsV2(address(this), TEST_VALUE); - - vm.expectRevert(abi.encodeWithSelector(IStakingRewardsV2.InsufficientBalance.selector, 0)); - unstakeEscrowSkipCooldownFundsV2(address(this), TEST_VALUE); } function test_Only_Owner_Can_Pause_Contract() public { @@ -186,8 +181,6 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { fundAndApproveAccountV2(address(this), TEST_VALUE); stakingRewardsV2.stake(TEST_VALUE); - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - // pause stakingRewardsV2.pauseStakingRewards(); @@ -247,8 +240,6 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { // fund and stake escrow stakeEscrowedFundsV2(address(this), TEST_VALUE); - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - // pause stakingRewardsV2.pauseStakingRewards(); @@ -571,7 +562,7 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { ) public { vm.assume(escrowAmount > 0); vm.assume(amountToEscrowStake > escrowAmount); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); createRewardEscrowEntryV2(address(this), escrowAmount, duration); vm.expectRevert( @@ -637,8 +628,6 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { // stake escrow stakeEscrowedFundsV2(address(this), TEST_VALUE); - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - // this would work if unstakeEscrow was called // but unstake is called so it fails vm.expectRevert(abi.encodeWithSelector(IStakingRewardsV2.InsufficientBalance.selector, 0)); @@ -649,8 +638,6 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { // stake escrow stakeEscrowedFundsV2(address(this), TEST_VALUE); - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - // exit - this fails because exit uses unstake not unstakeEscrow vm.expectRevert(IStakingRewardsV2.AmountZero.selector); stakingRewardsV2.exit(); @@ -841,14 +828,14 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { getReward //////////////////////////////////////////////////////////////*/ - function test_getReward_Increases_Balance_In_Escrow() public { + function test_getReward_Increases_Balance() public { fundAndApproveAccountV2(address(this), TEST_VALUE); - uint256 initialEscrowBalance = rewardEscrowV2.escrowedBalanceOf(address(this)); - // stake stakingRewardsV2.stake(TEST_VALUE); + uint256 initialBalance = kwenta.balanceOf(address(this)); + // configure reward rate vm.prank(address(rewardsNotifier)); stakingRewardsV2.notifyRewardAmount(TEST_VALUE, 0); @@ -859,8 +846,8 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { // get reward stakingRewardsV2.getReward(); - // check reward escrow balance increased - assertGt(rewardEscrowV2.escrowedBalanceOf(address(this)), initialEscrowBalance); + // check reward balance increased + assertGt(kwenta.balanceOf(address(this)), initialBalance); } function test_getReward_Increases_Usdc_Balance() public { @@ -1201,8 +1188,6 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { //////////////////////////////////////////////////////////////*/ function test_Cannot_unstake_If_Nothing_Staked() public { - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - vm.expectRevert(abi.encodeWithSelector(IStakingRewardsV2.InsufficientBalance.selector, 0)); stakingRewardsV2.unstake(TEST_VALUE); } @@ -1226,8 +1211,6 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { } function test_Cannot_unstake_0() public { - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - vm.expectRevert(IStakingRewardsV2.AmountZero.selector); stakingRewardsV2.unstake(0); } @@ -1237,13 +1220,8 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { //////////////////////////////////////////////////////////////*/ function test_Cannot_unstakeEscrow_If_None_Staked() public { - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - vm.expectRevert(abi.encodeWithSelector(IStakingRewardsV2.InsufficientBalance.selector, 0)); unstakeEscrowedFundsV2(address(this), TEST_VALUE); - - vm.expectRevert(abi.encodeWithSelector(IStakingRewardsV2.InsufficientBalance.selector, 0)); - unstakeEscrowSkipCooldownFundsV2(address(this), TEST_VALUE); } function test_unstakeEscrow_Does_Not_Change_Token_Balances() public { @@ -1253,9 +1231,6 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { uint256 initialTokenBalance = kwenta.balanceOf(address(this)); uint256 initialEscrowTokenBalance = kwenta.balanceOf(address(rewardEscrowV2)); - // pass cooldown period - vm.warp(block.timestamp + 2 weeks); - // unstake escrow unstakeEscrowedFundsV2(address(this), 1 weeks); @@ -1267,15 +1242,15 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { assertEq(initialEscrowTokenBalance, finalEscrowTokenBalance); } - function test_unstakeEscrowSkipCooldown_Does_Not_Change_Token_Balances() public { + function test_unstakeEscrowAdmin_Does_Not_Change_Token_Balances() public { // stake escrow stakeEscrowedFundsV2(address(this), 1 weeks); uint256 initialTokenBalance = kwenta.balanceOf(address(this)); uint256 initialEscrowTokenBalance = kwenta.balanceOf(address(rewardEscrowV2)); - // unstake escrow - unstakeEscrowSkipCooldownFundsV2(address(this), 1 weeks); + // unstake escrow admin + unstakeEscrowedFundsAdminV2(address(this), 1 weeks); uint256 finalTokenBalance = kwenta.balanceOf(address(this)); uint256 finalEscrowTokenBalance = kwenta.balanceOf(address(rewardEscrowV2)); @@ -1291,9 +1266,6 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { uint256 initialTotalSupply = stakingRewardsV2.totalSupply(); - // pass cooldown period - vm.warp(block.timestamp + 2 weeks); - // unstake escrow unstakeEscrowedFundsV2(address(this), 1 weeks); @@ -1303,14 +1275,14 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { assertEq(initialTotalSupply - 1 weeks, finalTotalSupply); } - function test_unstakeEscrowSkipCooldown_Does_Change_totalSupply() public { + function test_unstakeEscrowAdmin_Does_Change_totalSupply() public { // stake escrow stakeEscrowedFundsV2(address(this), 1 weeks); uint256 initialTotalSupply = stakingRewardsV2.totalSupply(); - // unstake escrow - unstakeEscrowSkipCooldownFundsV2(address(this), 1 weeks); + // unstake escrow admin + unstakeEscrowedFundsAdminV2(address(this), 1 weeks); uint256 finalTotalSupply = stakingRewardsV2.totalSupply(); @@ -1324,9 +1296,6 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { uint256 initialBalance = stakingRewardsV2.balanceOf(address(this)); - // pass cooldown period - vm.warp(block.timestamp + 2 weeks); - // unstake escrow unstakeEscrowedFundsV2(address(this), 1 weeks); @@ -1336,14 +1305,14 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { assertEq(initialBalance - 1 weeks, finalBalance); } - function test_unstakeEscrowSkipCooldown_Does_Change_Balances_Mapping() public { + function test_unstakeEscrowAdmin_Does_Change_Balances_Mapping() public { // stake escrow stakeEscrowedFundsV2(address(this), 1 weeks); uint256 initialBalance = stakingRewardsV2.balanceOf(address(this)); - // unstake escrow - unstakeEscrowSkipCooldownFundsV2(address(this), 1 weeks); + // unstake escrow admin + unstakeEscrowedFundsAdminV2(address(this), 1 weeks); uint256 finalBalance = stakingRewardsV2.balanceOf(address(this)); @@ -1357,9 +1326,6 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { uint256 initialEscrowBalance = stakingRewardsV2.escrowedBalanceOf(address(this)); - // pass cooldown period - vm.warp(block.timestamp + 2 weeks); - // unstake escrow unstakeEscrowedFundsV2(address(this), 1 weeks); @@ -1369,53 +1335,39 @@ contract StakingRewardsV2Test is DefaultStakingV2Setup { assertEq(initialEscrowBalance - 1 weeks, finalEscrowBalance); } - function test_unstakeEscrowSkipCooldown_Does_Change_Escrowed_Balances_Mapping() public { + function test_unstakeEscrowAdmin_Does_Change_Escrowed_Balances_Mapping() public { // stake escrow stakeEscrowedFundsV2(address(this), 1 weeks); uint256 initialEscrowBalance = stakingRewardsV2.escrowedBalanceOf(address(this)); - // unstake escrow - unstakeEscrowSkipCooldownFundsV2(address(this), 1 weeks); + // unstake escrow admin + unstakeEscrowedFundsAdminV2(address(this), 1 weeks); uint256 finalEscrowBalance = stakingRewardsV2.escrowedBalanceOf(address(this)); // check balance decreased assertEq(initialEscrowBalance - 1 weeks, finalEscrowBalance); } - + function test_Cannot_unstakeEscrow_More_Than_Escrow_Staked() public { // stake escrow stakeEscrowedFundsV2(address(this), 1 weeks); - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - // unstake more escrow vm.expectRevert( abi.encodeWithSelector(IStakingRewardsV2.InsufficientBalance.selector, 1 weeks) ); unstakeEscrowedFundsV2(address(this), 2 weeks); - - // unstake more escrow - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.InsufficientBalance.selector, 1 weeks) - ); - unstakeEscrowSkipCooldownFundsV2(address(this), 2 weeks); } function test_Cannot_unstakeEscrow_0() public { // stake escrow stakeEscrowedFundsV2(address(this), 1 weeks); - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - // unstake 0 escrow vm.expectRevert(IStakingRewardsV2.AmountZero.selector); unstakeEscrowedFundsV2(address(this), 0); - - // unstake 0 escrow - vm.expectRevert(IStakingRewardsV2.AmountZero.selector); - unstakeEscrowSkipCooldownFundsV2(address(this), 0); } /*////////////////////////////////////////////////////////////// diff --git a/test/foundry/unit/StakingRewardsV2/StakingRewardsV2Compound.t.sol b/test/foundry/unit/StakingRewardsV2/StakingRewardsV2Compound.t.sol index 1721d5ae1..a8cb3a9bc 100644 --- a/test/foundry/unit/StakingRewardsV2/StakingRewardsV2Compound.t.sol +++ b/test/foundry/unit/StakingRewardsV2/StakingRewardsV2Compound.t.sol @@ -13,11 +13,13 @@ contract StakingRewardsV2CompoundTests is DefaultStakingV2Setup { function test_compound() public { fundAndApproveAccountV2(address(this), TEST_VALUE); - uint256 initialEscrowBalance = rewardEscrowV2.escrowedBalanceOf(address(this)); // stake stakingRewardsV2.stake(TEST_VALUE); + uint256 initialBalance = kwenta.balanceOf(address(this)); + uint256 initialStakedBalance = stakingRewardsV2.balanceOf(address(this)); + // configure reward rate addNewRewardsToStakingRewardsV2(TEST_VALUE, 0); @@ -27,15 +29,12 @@ contract StakingRewardsV2CompoundTests is DefaultStakingV2Setup { // compound rewards stakingRewardsV2.compound(); - // check reward escrow balance increased - uint256 finalEscrowBalance = rewardEscrowV2.escrowedBalanceOf(address(this)); - assertGt(finalEscrowBalance, initialEscrowBalance); - - // check all escrowed rewards were staked - uint256 totalRewards = finalEscrowBalance - initialEscrowBalance; - assertEq(totalRewards, stakingRewardsV2.escrowedBalanceOf(address(this))); - assertEq(totalRewards + TEST_VALUE, stakingRewardsV2.balanceOf(address(this))); - assertEq(rewardEscrowV2.unstakedEscrowedBalanceOf(address(this)), 0); + // check all rewards were staked and that staker balance increased + uint256 finalBalance = kwenta.balanceOf(address(this)); + uint256 finalStakedBalance = stakingRewardsV2.balanceOf(address(this)); + assertEq(initialBalance, finalBalance); + assertGt(finalStakedBalance, initialStakedBalance); + assertGt(finalStakedBalance, TEST_VALUE); } function test_compound_Fuzz(uint32 initialStake, uint32 newRewards) public { @@ -45,11 +44,12 @@ contract StakingRewardsV2CompoundTests is DefaultStakingV2Setup { fundAndApproveAccountV2(address(this), initialStake); - uint256 initialEscrowBalance = rewardEscrowV2.escrowedBalanceOf(address(this)); - // stake stakingRewardsV2.stake(initialStake); + uint256 initialBalance = kwenta.balanceOf(address(this)); + uint256 initialStakedBalance = stakingRewardsV2.balanceOf(address(this)); + // configure reward rate addNewRewardsToStakingRewardsV2(newRewards, 0); @@ -59,15 +59,12 @@ contract StakingRewardsV2CompoundTests is DefaultStakingV2Setup { // compound rewards stakingRewardsV2.compound(); - // check reward escrow balance increased - uint256 finalEscrowBalance = rewardEscrowV2.escrowedBalanceOf(address(this)); - assertGt(finalEscrowBalance, initialEscrowBalance); - - // check all escrowed rewards were staked - uint256 totalRewards = finalEscrowBalance - initialEscrowBalance; - assertEq(totalRewards, stakingRewardsV2.escrowedBalanceOf(address(this))); - assertEq(totalRewards + initialStake, stakingRewardsV2.balanceOf(address(this))); - assertEq(rewardEscrowV2.unstakedEscrowedBalanceOf(address(this)), 0); + // check all rewards were staked and that staker balance increased + uint256 finalBalance = kwenta.balanceOf(address(this)); + uint256 finalStakedBalance = stakingRewardsV2.balanceOf(address(this)); + assertEq(initialBalance, finalBalance); + assertGt(finalStakedBalance, initialStakedBalance); + assertGt(stakingRewardsV2.balanceOf(address(this)), initialStake); } /*////////////////////////////////////////////////////////////// @@ -112,7 +109,7 @@ contract StakingRewardsV2CompoundTests is DefaultStakingV2Setup { vm.expectEmit(true, true, false, true); emit RewardPaid(address(this), 1 weeks); vm.expectEmit(true, true, false, true); - emit EscrowStaked(address(this), 1 weeks); + emit Staked(address(this), 1 weeks); // compound rewards stakingRewardsV2.compound(); diff --git a/test/foundry/unit/StakingRewardsV2/StakingRewardsV2OnBehalfActionsTests.t.sol b/test/foundry/unit/StakingRewardsV2/StakingRewardsV2OnBehalfActionsTests.t.sol index b5981e114..c93a19614 100644 --- a/test/foundry/unit/StakingRewardsV2/StakingRewardsV2OnBehalfActionsTests.t.sol +++ b/test/foundry/unit/StakingRewardsV2/StakingRewardsV2OnBehalfActionsTests.t.sol @@ -90,7 +90,7 @@ contract StakingRewardsV2OnBehalfActionsTests is DefaultStakingV2Setup { address caller ) public { vm.assume(escrowAmount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); vm.assume(owner != address(0)); vm.assume(operator != address(0)); vm.assume(caller != address(0)); @@ -175,76 +175,6 @@ contract StakingRewardsV2OnBehalfActionsTests is DefaultStakingV2Setup { stakingRewardsV2.approveOperator(owner, true); } - /*////////////////////////////////////////////////////////////// - Get Reward On Behalf - //////////////////////////////////////////////////////////////*/ - - function test_getRewardOnBehalf() public { - fundAccountAndStakeV2(address(this), TEST_VALUE); - - // assert initial rewards are 0 - assertEq(rewardEscrowV2.escrowedBalanceOf(address(this)), 0); - assertEq(rewardEscrowV2.escrowedBalanceOf(user1), 0); - - // send in 604800 (1 week) of rewards - (using 1 week for round numbers) - addNewRewardsToStakingRewardsV2(1 weeks, 1 weeks); - - // fast forward 1 week - one complete period - vm.warp(block.timestamp + stakingRewardsV2.rewardsDuration()); - - // approve operator - stakingRewardsV2.approveOperator(user1, true); - - // claim rewards on behalf - vm.prank(user1); - stakingRewardsV2.getRewardOnBehalf(address(this)); - - // check rewards - assertEq(rewardEscrowV2.escrowedBalanceOf(address(this)), 1 weeks); - assertEq(rewardEscrowV2.escrowedBalanceOf(user1), 0); - assertEq(usdc.balanceOf(address(this)), 1 weeks); - assertEq(usdc.balanceOf(user1), 0); - } - - function test_getRewardOnBehalf_Fuzz( - uint32 fundingAmount, - uint32 newRewards, - address owner, - address operator - ) public { - vm.assume(fundingAmount > 0); - vm.assume(newRewards > stakingRewardsV2.rewardsDuration()); - vm.assume(owner != address(0)); - vm.assume(operator != address(0)); - vm.assume(operator != owner); - - fundAccountAndStakeV2(owner, fundingAmount); - - // assert initial rewards are 0 - assertEq(rewardEscrowV2.escrowedBalanceOf(owner), 0); - assertEq(rewardEscrowV2.escrowedBalanceOf(operator), 0); - - // send in rewards - addNewRewardsToStakingRewardsV2(newRewards, newRewards); - - // fast forward 1 week - one complete period - vm.warp(block.timestamp + stakingRewardsV2.rewardsDuration()); - - // approve operator - vm.prank(owner); - stakingRewardsV2.approveOperator(operator, true); - - // claim rewards on behalf - vm.prank(operator); - stakingRewardsV2.getRewardOnBehalf(owner); - - // check rewards - assertGt(rewardEscrowV2.escrowedBalanceOf(owner), 0); - assertEq(rewardEscrowV2.escrowedBalanceOf(operator), 0); - assertGt(usdc.balanceOf(owner), 0); - assertEq(usdc.balanceOf(operator), 0); - } - /*////////////////////////////////////////////////////////////// Stake Escrow On Behalf //////////////////////////////////////////////////////////////*/ @@ -275,7 +205,7 @@ contract StakingRewardsV2OnBehalfActionsTests is DefaultStakingV2Setup { uint24 duration ) public { vm.assume(escrowAmount > 0); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); vm.assume(owner != address(0)); vm.assume(operator != address(0)); vm.assume(owner != operator); @@ -334,7 +264,7 @@ contract StakingRewardsV2OnBehalfActionsTests is DefaultStakingV2Setup { ) public { vm.assume(escrowAmount > 0); vm.assume(amountToEscrowStake > escrowAmount); - vm.assume(duration >= stakingRewardsV2.cooldownPeriod()); + vm.assume(duration > 0); vm.assume(owner != address(0)); vm.assume(operator != address(0)); vm.assume(owner != operator); @@ -356,18 +286,20 @@ contract StakingRewardsV2OnBehalfActionsTests is DefaultStakingV2Setup { } /*////////////////////////////////////////////////////////////// - Get Reward And Stake On Behalf + Get Reward On Behalf //////////////////////////////////////////////////////////////*/ - function test_Get_Reward_And_Stake_On_Behalf() public { + function test_Get_Reward_On_Behalf() public { fundAccountAndStakeV2(address(this), TEST_VALUE); // assert initial rewards are 0 - assertEq(rewardEscrowV2.escrowedBalanceOf(address(this)), 0); - assertEq(rewardEscrowV2.escrowedBalanceOf(user1), 0); + assertEq(kwenta.balanceOf(address(this)), 0); + assertEq(kwenta.balanceOf(user1), 0); + assertEq(usdc.balanceOf(address(this)), 0); + assertEq(usdc.balanceOf(user1), 0); // send in 604800 (1 week) of rewards - (using 1 week for round numbers) - addNewRewardsToStakingRewardsV2(1 weeks, 0); + addNewRewardsToStakingRewardsV2(1 weeks, 1 weeks); // fast forward 1 week - one complete period vm.warp(block.timestamp + stakingRewardsV2.rewardsDuration()); @@ -380,26 +312,22 @@ contract StakingRewardsV2OnBehalfActionsTests is DefaultStakingV2Setup { stakingRewardsV2.getRewardOnBehalf(address(this)); // check rewards - assertEq(rewardEscrowV2.escrowedBalanceOf(address(this)), 1 weeks); - assertEq(rewardEscrowV2.escrowedBalanceOf(user1), 0); - - // stake escrow on behalf - vm.prank(user1); - stakingRewardsV2.stakeEscrowOnBehalf(address(this), 1 weeks); - - // check final escrowed balances - assertEq(stakingRewardsV2.escrowedBalanceOf(address(this)), 1 weeks); - assertEq(stakingRewardsV2.escrowedBalanceOf(user1), 0); + assertEq(kwenta.balanceOf(address(this)), 1 weeks); + assertEq(kwenta.balanceOf(user1), 0); + assertEq(usdc.balanceOf(address(this)), 1 weeks); + assertEq(usdc.balanceOf(user1), 0); } - function test_Get_Reward_And_Stake_On_Behalf_Fuzz( + function test_Get_Reward_On_Behalf_Fuzz( uint32 fundingAmount, uint32 newRewards, + uint32 newUsdcRewards, address owner, address operator ) public { vm.assume(fundingAmount > 0); vm.assume(newRewards > stakingRewardsV2.rewardsDuration()); + vm.assume(newUsdcRewards > stakingRewardsV2.rewardsDuration()); vm.assume(owner != address(0)); vm.assume(operator != address(0)); vm.assume(operator != owner); @@ -407,11 +335,13 @@ contract StakingRewardsV2OnBehalfActionsTests is DefaultStakingV2Setup { fundAccountAndStakeV2(owner, fundingAmount); // assert initial rewards are 0 - assertEq(rewardEscrowV2.escrowedBalanceOf(owner), 0); - assertEq(rewardEscrowV2.escrowedBalanceOf(operator), 0); + assertEq(kwenta.balanceOf(owner), 0); + assertEq(kwenta.balanceOf(operator), 0); + assertEq(usdc.balanceOf(owner), 0); + assertEq(usdc.balanceOf(operator), 0); // send in rewards - addNewRewardsToStakingRewardsV2(newRewards, 0); + addNewRewardsToStakingRewardsV2(newRewards, newUsdcRewards); // fast forward 1 week - one complete period vm.warp(block.timestamp + stakingRewardsV2.rewardsDuration()); @@ -425,17 +355,10 @@ contract StakingRewardsV2OnBehalfActionsTests is DefaultStakingV2Setup { stakingRewardsV2.getRewardOnBehalf(owner); // check rewards - uint256 rewardEscrowBalance = rewardEscrowV2.escrowedBalanceOf(owner); - assertGt(rewardEscrowBalance, 0); - assertEq(rewardEscrowV2.escrowedBalanceOf(operator), 0); - - // stake escrow on behalf - vm.prank(operator); - stakingRewardsV2.stakeEscrowOnBehalf(owner, rewardEscrowBalance); - - // check final escrowed balances - assertEq(stakingRewardsV2.escrowedBalanceOf(owner), rewardEscrowBalance); - assertEq(stakingRewardsV2.escrowedBalanceOf(operator), 0); + assertGt(kwenta.balanceOf(owner), 0); + assertEq(kwenta.balanceOf(operator), 0); + assertGt(usdc.balanceOf(owner), 0); + assertEq(usdc.balanceOf(operator), 0); } /*////////////////////////////////////////////////////////////// @@ -444,11 +367,13 @@ contract StakingRewardsV2OnBehalfActionsTests is DefaultStakingV2Setup { function test_compoundOnBehalf() public { fundAndApproveAccountV2(address(this), TEST_VALUE); - uint256 initialEscrowBalance = rewardEscrowV2.escrowedBalanceOf(address(this)); // stake stakingRewardsV2.stake(TEST_VALUE); + uint256 initialBalance = kwenta.balanceOf(address(this)); + uint256 initialStakedBalance = stakingRewardsV2.balanceOf(address(this)); + // configure reward rate addNewRewardsToStakingRewardsV2(TEST_VALUE, 0); @@ -462,15 +387,12 @@ contract StakingRewardsV2OnBehalfActionsTests is DefaultStakingV2Setup { vm.prank(user1); stakingRewardsV2.compoundOnBehalf(address(this)); - // check reward escrow balance increased - uint256 finalEscrowBalance = rewardEscrowV2.escrowedBalanceOf(address(this)); - assertGt(finalEscrowBalance, initialEscrowBalance); - - // check all escrowed rewards were staked - uint256 totalRewards = finalEscrowBalance - initialEscrowBalance; - assertEq(totalRewards, stakingRewardsV2.escrowedBalanceOf(address(this))); - assertEq(totalRewards + TEST_VALUE, stakingRewardsV2.balanceOf(address(this))); - assertEq(rewardEscrowV2.unstakedEscrowedBalanceOf(address(this)), 0); + // check all rewards were staked and that staker balance increased + uint256 finalBalance = kwenta.balanceOf(address(this)); + uint256 finalStakedBalance = stakingRewardsV2.balanceOf(address(this)); + assertEq(initialBalance, finalBalance); + assertGt(finalStakedBalance, initialStakedBalance); + assertGt(stakingRewardsV2.balanceOf(address(this)), TEST_VALUE); } function test_compoundOnBehalf_Fuzz( @@ -488,12 +410,13 @@ contract StakingRewardsV2OnBehalfActionsTests is DefaultStakingV2Setup { fundAndApproveAccountV2(owner, initialStake); - uint256 initialEscrowBalance = rewardEscrowV2.escrowedBalanceOf(owner); - // stake vm.prank(owner); stakingRewardsV2.stake(initialStake); + uint256 initialBalance = kwenta.balanceOf(owner); + uint256 initialStakedBalance = stakingRewardsV2.balanceOf(owner); + // configure reward rate addNewRewardsToStakingRewardsV2(newRewards, 0); @@ -508,15 +431,12 @@ contract StakingRewardsV2OnBehalfActionsTests is DefaultStakingV2Setup { vm.prank(operator); stakingRewardsV2.compoundOnBehalf(owner); - // check reward escrow balance increased - uint256 finalEscrowBalance = rewardEscrowV2.escrowedBalanceOf(owner); - assertGt(finalEscrowBalance, initialEscrowBalance); - - // check all escrowed rewards were staked - uint256 totalRewards = finalEscrowBalance - initialEscrowBalance; - assertEq(totalRewards, stakingRewardsV2.escrowedBalanceOf(owner)); - assertEq(totalRewards + initialStake, stakingRewardsV2.balanceOf(owner)); - assertEq(rewardEscrowV2.unstakedEscrowedBalanceOf(owner), 0); + // check all rewards were staked and that staker balance increased + uint256 finalBalance = kwenta.balanceOf(owner); + uint256 finalStakedBalance = stakingRewardsV2.balanceOf(owner); + assertEq(initialBalance, finalBalance); + assertGt(finalStakedBalance, initialStakedBalance); + assertGt(stakingRewardsV2.balanceOf(owner), initialStake); } /*////////////////////////////////////////////////////////////// diff --git a/test/foundry/unit/StakingRewardsV2/StakingV2Checkpointing.t.sol b/test/foundry/unit/StakingRewardsV2/StakingV2Checkpointing.t.sol index 97920dd68..e4a06f683 100644 --- a/test/foundry/unit/StakingRewardsV2/StakingV2Checkpointing.t.sol +++ b/test/foundry/unit/StakingRewardsV2/StakingV2Checkpointing.t.sol @@ -23,9 +23,6 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { assertEq(blk, block.number); assertEq(value, TEST_VALUE); - // move beyond cold period - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - // update block timestamp vm.warp(block.timestamp + 1); vm.roll(block.number + 1); @@ -55,9 +52,6 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { assertEq(blk, block.number); assertEq(value, TEST_VALUE * 2); - // move beyond cold period - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - // update block timestamp vm.warp(block.timestamp + 1); vm.roll(block.number + 1); @@ -88,9 +82,6 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { assertEq(blk, block.number); assertEq(value, TEST_VALUE); - // move beyond cold period - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - // update block timestamp vm.warp(block.timestamp + 1); vm.roll(block.number + 1); @@ -120,9 +111,6 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { assertEq(blk, block.number); assertEq(value, TEST_VALUE * 2); - // move beyond cold period - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - // update block timestamp vm.warp(block.timestamp + 1); vm.roll(block.number + 1); @@ -173,7 +161,7 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { assertEq(value, previousTotal + amountToStake); // move beyond cold period - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); + vm.warp(block.timestamp + 2 weeks); // update block timestamp vm.warp(block.timestamp + timestampAdvance); @@ -229,7 +217,7 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { assertEq(value, previousTotal + amountToStake); // move beyond cold period - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); + vm.warp(block.timestamp + 2 weeks); // update block timestamp vm.warp(block.timestamp + timestampAdvance); @@ -269,9 +257,6 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { assertEq(blk, block.number); assertEq(value, TEST_VALUE); - // move beyond cold period - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - // update block timestamp vm.warp(block.timestamp + 1); vm.roll(block.number + 1); @@ -301,9 +286,6 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { assertEq(blk, block.number); assertEq(value, TEST_VALUE * 2); - // move beyond cold period - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - // update block timestamp vm.warp(block.timestamp + 1); vm.roll(block.number + 1); @@ -354,7 +336,7 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { assertEq(value, previousTotal + amountToStake); // move beyond cold period - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); + vm.warp(block.timestamp + 2 weeks); // update block timestamp vm.warp(block.timestamp + timestampAdvance); @@ -393,9 +375,6 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { assertEq(blk, block.number); assertEq(value, TEST_VALUE); - // move beyond cold period - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - // update block timestamp vm.warp(block.timestamp + 1); vm.roll(block.number + 1); @@ -424,9 +403,6 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { assertEq(blk, block.number); assertEq(value, TEST_VALUE * 2); - // move beyond cold period - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - // update block timestamp vm.warp(block.timestamp + 1); vm.roll(block.number + 1); @@ -456,9 +432,6 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { assertEq(blk, block.number); assertEq(value, TEST_VALUE); - // move beyond cold period - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); - // update block timestamp vm.warp(block.timestamp + 1); vm.roll(block.number + 1); @@ -513,7 +486,7 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { assertEq(value, previousTotal + amountToStake); // move beyond cold period - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); + vm.warp(block.timestamp + 2 weeks); // update block timestamp vm.warp(block.timestamp + timestampAdvance); @@ -565,14 +538,14 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { } function test_balanceAtTime_With_Unstake_Before_Block() public { - uint256 timestampToFind = xCooldownPeriods(4); + uint256 timestampToFind = xPeriods(4); uint256 expectedValue; uint256 totalStaked; for (uint256 i = 0; i < 10; i++) { uint256 amount = TEST_VALUE; totalStaked += amount; - if (block.timestamp == xCooldownPeriods(2)) { + if (block.timestamp == xPeriods(2)) { stakingRewardsV2.unstake(amount); totalStaked -= amount; } @@ -580,7 +553,7 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { expectedValue = totalStaked; } fundAccountAndStakeV2(address(this), amount); - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); + vm.warp(block.timestamp + 1); } uint256 value = stakingRewardsV2.balanceAtTime(address(this), timestampToFind); @@ -589,14 +562,14 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { } function test_balanceAtTime_With_Unstake_After_Block() public { - uint256 timestampToFind = xCooldownPeriods(4); + uint256 timestampToFind = xPeriods(4); uint256 expectedValue; uint256 totalStaked; for (uint256 i = 0; i < 10; i++) { uint256 amount = TEST_VALUE; totalStaked += amount; - if (block.timestamp == xCooldownPeriods(5)) { + if (block.timestamp == xPeriods(5)) { stakingRewardsV2.unstake(amount); totalStaked -= amount; } @@ -604,7 +577,7 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { expectedValue = totalStaked; } fundAccountAndStakeV2(address(this), amount); - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); + vm.warp(block.timestamp + 1); } uint256 value = stakingRewardsV2.balanceAtTime(address(this), timestampToFind); @@ -613,7 +586,7 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { } function test_balanceAtTime_With_Unstake_Before_And_After_Block() public { - uint256 timestampToFind = xCooldownPeriods(4); + uint256 timestampToFind = xPeriods(4); uint256 expectedValue; uint256 totalStaked; @@ -621,15 +594,15 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { uint256 amount = TEST_VALUE; totalStaked += amount; fundAccountAndStakeV2(address(this), amount); - if (block.timestamp == xCooldownPeriods(2)) { - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); + if (block.timestamp == xPeriods(2)) { + vm.warp(block.timestamp + 1); stakingRewardsV2.unstake(amount); stakingRewardsV2.unstake(amount); totalStaked -= amount; totalStaked -= amount; } - if (block.timestamp == xCooldownPeriods(5)) { - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); + if (block.timestamp == xPeriods(5)) { + vm.warp(block.timestamp + 1); stakingRewardsV2.unstake(amount); stakingRewardsV2.unstake(amount); stakingRewardsV2.unstake(amount); @@ -640,7 +613,7 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { if (timestampToFind == block.timestamp) { expectedValue = totalStaked; } - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod()); + vm.warp(block.timestamp + 1); } uint256 value = stakingRewardsV2.balanceAtTime(address(this), timestampToFind); @@ -957,7 +930,7 @@ contract StakingV2CheckpointingTests is DefaultStakingV2Setup { Helpers //////////////////////////////////////////////////////////////*/ - function xCooldownPeriods(uint256 numCooldowns) public view returns (uint256) { - return 1 + (numCooldowns * stakingRewardsV2.cooldownPeriod()); + function xPeriods(uint256 numCooldowns) public pure returns (uint256) { + return 1 + (numCooldowns * 1); } } diff --git a/test/foundry/unit/StakingRewardsV2/StakingV2CooldownPeriod.t.sol b/test/foundry/unit/StakingRewardsV2/StakingV2CooldownPeriod.t.sol deleted file mode 100644 index b4aaa2a0d..000000000 --- a/test/foundry/unit/StakingRewardsV2/StakingV2CooldownPeriod.t.sol +++ /dev/null @@ -1,303 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.19; - -import {console} from "forge-std/Test.sol"; -import {DefaultStakingV2Setup} from "../../utils/setup/DefaultStakingV2Setup.t.sol"; -import {IStakingRewardsV2} from "../../../../contracts/interfaces/IStakingRewardsV2.sol"; -import "../../utils/Constants.t.sol"; - -contract StakingV2CooldownPeriodTests is DefaultStakingV2Setup { - /*////////////////////////////////////////////////////////////// - Unstaking During Cooldown - //////////////////////////////////////////////////////////////*/ - - function test_Cannot_unstake_During_Cooldown() public { - // stake - fundAccountAndStakeV2(address(this), TEST_VALUE); - - uint256 cooldownPeriod = stakingRewardsV2.cooldownPeriod(); - uint256 canUnstakeAt = block.timestamp + cooldownPeriod; - uint256 stakedAt = block.timestamp; - - // unstake immediately - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.MustWaitForUnlock.selector, canUnstakeAt) - ); - stakingRewardsV2.unstake(TEST_VALUE); - - // unstake midway through - vm.warp(stakedAt + cooldownPeriod / 2); - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.MustWaitForUnlock.selector, canUnstakeAt) - ); - stakingRewardsV2.unstake(TEST_VALUE); - - // unstake 1 sec before period ends - vm.warp(stakedAt + cooldownPeriod - 1); - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.MustWaitForUnlock.selector, canUnstakeAt) - ); - stakingRewardsV2.unstake(TEST_VALUE); - } - - function test_Cannot_unstake_During_Cooldown_Fuzz(uint32 stakeAmount, uint32 waitTime) public { - vm.assume(stakeAmount > 0); - - // stake - fundAccountAndStakeV2(address(this), stakeAmount); - - uint256 cooldownPeriod = stakingRewardsV2.cooldownPeriod(); - uint256 canUnstakeAt = block.timestamp + cooldownPeriod; - uint256 stakedAt = block.timestamp; - - // unstake - vm.warp(stakedAt + waitTime); - if (waitTime < cooldownPeriod) { - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.MustWaitForUnlock.selector, canUnstakeAt) - ); - } - stakingRewardsV2.unstake(stakeAmount); - } - - function test_Cannot_unstakeEscrow_During_Cooldown() public { - // stake - stakeEscrowedFundsV2(address(this), TEST_VALUE); - - uint256 cooldownPeriod = stakingRewardsV2.cooldownPeriod(); - uint256 canUnstakeAt = block.timestamp + cooldownPeriod; - uint256 stakedAt = block.timestamp; - - // unstake immediately - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.MustWaitForUnlock.selector, canUnstakeAt) - ); - unstakeEscrowedFundsV2(address(this), TEST_VALUE); - - // unstake midway through - vm.warp(stakedAt + cooldownPeriod / 2); - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.MustWaitForUnlock.selector, canUnstakeAt) - ); - unstakeEscrowedFundsV2(address(this), TEST_VALUE); - - // unstake 1 sec before period ends - vm.warp(stakedAt + cooldownPeriod - 1); - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.MustWaitForUnlock.selector, canUnstakeAt) - ); - unstakeEscrowedFundsV2(address(this), TEST_VALUE); - } - - function test_Cannot_unstakeEscrow_During_Cooldown_Fuzz(uint32 stakeAmount, uint32 waitTime) - public - { - vm.assume(stakeAmount > 0); - - // stake - stakeEscrowedFundsV2(address(this), stakeAmount); - - uint256 cooldownPeriod = stakingRewardsV2.cooldownPeriod(); - uint256 canUnstakeAt = block.timestamp + cooldownPeriod; - uint256 stakedAt = block.timestamp; - - // unstake - vm.warp(stakedAt + waitTime); - if (waitTime < cooldownPeriod) { - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.MustWaitForUnlock.selector, canUnstakeAt) - ); - } - unstakeEscrowedFundsV2(address(this), stakeAmount); - } - - /*////////////////////////////////////////////////////////////// - Staking During Cooldown - //////////////////////////////////////////////////////////////*/ - - function test_Can_stake_More_During_Cooldown() public { - // stake once - fundAndApproveAccountV2(address(this), TEST_VALUE * 3); - stakingRewardsV2.stake(TEST_VALUE); - - // stake immediately again - stakingRewardsV2.stake(TEST_VALUE); - - // stake half the cooldown period later again - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod() / 2); - stakingRewardsV2.stake(TEST_VALUE); - } - - function test_Can_stakeEscrow_More_During_Cooldown() public { - // stake once - stakeEscrowedFundsV2(address(this), TEST_VALUE); - - // stake immediately again - stakeEscrowedFundsV2(address(this), TEST_VALUE); - - // stake half the cooldown period later again - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod() / 2); - stakeEscrowedFundsV2(address(this), TEST_VALUE); - } - - function test_Staking_During_Cooldown_Extends_Wait() public { - // stake - fundAndApproveAccountV2(address(this), TEST_VALUE * 3); - stakingRewardsV2.stake(TEST_VALUE); - - // stake half the cooldown period later again - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod() / 2); - stakingRewardsV2.stake(TEST_VALUE); - - // expected can unstakeAt time is now the cooldown period from now - uint256 canUnstakeAt = block.timestamp + stakingRewardsV2.cooldownPeriod(); - - // cannot unstake another half period later - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod() / 2); - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.MustWaitForUnlock.selector, canUnstakeAt) - ); - stakingRewardsV2.unstake(TEST_VALUE); - } - - function test_Staking_Escrow_During_Cooldown_Extends_Wait() public { - // stake - stakeEscrowedFundsV2(address(this), TEST_VALUE); - - // stake half the cooldown period later again - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod() / 2); - stakeEscrowedFundsV2(address(this), TEST_VALUE); - - // expected can unstakeAt time is now the cooldown period from now - uint256 canUnstakeAt = block.timestamp + stakingRewardsV2.cooldownPeriod(); - - // cannot unstake another half period later - vm.warp(block.timestamp + stakingRewardsV2.cooldownPeriod() / 2); - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.MustWaitForUnlock.selector, canUnstakeAt) - ); - unstakeEscrowedFundsV2(address(this), TEST_VALUE); - } - - /*////////////////////////////////////////////////////////////// - Changing Cooldown Period - //////////////////////////////////////////////////////////////*/ - - function test_setCooldownPeriod_Is_Only_Owner() public { - vm.expectRevert("Ownable: caller is not the owner"); - vm.prank(user1); - stakingRewardsV2.setCooldownPeriod(1 weeks); - } - - function test_setCooldownPeriod() public { - uint256 newCooldownPeriod = 1 weeks; - - // Expect correct event emitted - vm.expectEmit(true, false, false, true); - emit CooldownPeriodUpdated(newCooldownPeriod); - - // Set new cooldown period - stakingRewardsV2.setCooldownPeriod(newCooldownPeriod); - - // Check cooldown period is updated - assertEq(stakingRewardsV2.cooldownPeriod(), newCooldownPeriod); - - // stake - fundAccountAndStakeV2(address(this), TEST_VALUE); - - // stake escrow - stakeEscrowedFundsV2(address(this), TEST_VALUE); - - // move forward new cooldown period - vm.warp(block.timestamp + newCooldownPeriod); - - // unstake - stakingRewardsV2.unstake(TEST_VALUE); - - // unstake escrow - unstakeEscrowedFundsV2(address(this), TEST_VALUE); - } - - function test_setCooldownPeriod_Fuzz(uint128 newCooldownPeriod, uint128 timeJump) public { - vm.assume(newCooldownPeriod > stakingRewardsV2.MIN_COOLDOWN_PERIOD()); - vm.assume(newCooldownPeriod < stakingRewardsV2.MAX_COOLDOWN_PERIOD()); - - // Expect correct event emitted - vm.expectEmit(true, false, false, true); - emit CooldownPeriodUpdated(newCooldownPeriod); - - // Set new cooldown period - stakingRewardsV2.setCooldownPeriod(newCooldownPeriod); - - // Check cooldown period is updated - assertEq(stakingRewardsV2.cooldownPeriod(), newCooldownPeriod); - - // stake - fundAccountAndStakeV2(address(this), TEST_VALUE); - - // stake escrow - stakeEscrowedFundsV2(address(this), TEST_VALUE); - - uint256 canUnstakeAt = block.timestamp + newCooldownPeriod; - - // move forward new cooldown period - vm.warp(block.timestamp + timeJump); - - if (timeJump < newCooldownPeriod) { - // Expect revert if unstaking before cooldown period - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.MustWaitForUnlock.selector, canUnstakeAt) - ); - } - // unstake - stakingRewardsV2.unstake(TEST_VALUE); - - if (timeJump < newCooldownPeriod) { - // Expect revert if unstaking before cooldown period - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.MustWaitForUnlock.selector, canUnstakeAt) - ); - } - // unstake escrow - unstakeEscrowedFundsV2(address(this), TEST_VALUE); - } - - function test_setCooldownPeriod_Range() public { - // Expect revert if cooldown period is too low - uint256 minPeriod = stakingRewardsV2.MIN_COOLDOWN_PERIOD(); - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.CooldownPeriodTooLow.selector, minPeriod) - ); - stakingRewardsV2.setCooldownPeriod(minPeriod - 1); - - // Expect revert if cooldown period is too high - uint256 maxPeriod = stakingRewardsV2.MAX_COOLDOWN_PERIOD(); - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.CooldownPeriodTooHigh.selector, maxPeriod) - ); - stakingRewardsV2.setCooldownPeriod(maxPeriod + 1); - } - - function test_setCooldownPeriod_Range_Fuzz(uint256 newCooldownPeriod) public { - // Expect revert if cooldown period is too low - uint256 minPeriod = stakingRewardsV2.MIN_COOLDOWN_PERIOD(); - if (newCooldownPeriod < minPeriod) { - vm.expectRevert( - abi.encodeWithSelector(IStakingRewardsV2.CooldownPeriodTooLow.selector, minPeriod) - ); - } else { - // Expect revert if cooldown period is too high - uint256 maxPeriod = stakingRewardsV2.MAX_COOLDOWN_PERIOD(); - if (newCooldownPeriod > maxPeriod) { - vm.expectRevert( - abi.encodeWithSelector( - IStakingRewardsV2.CooldownPeriodTooHigh.selector, maxPeriod - ) - ); - } - } - - // Set new cooldown period - stakingRewardsV2.setCooldownPeriod(newCooldownPeriod); - } -} diff --git a/test/foundry/unit/StakingRewardsV2/StakingV2RewardCalculations.t.sol b/test/foundry/unit/StakingRewardsV2/StakingV2RewardCalculations.t.sol index 7aa97ea5b..de0979fbe 100644 --- a/test/foundry/unit/StakingRewardsV2/StakingV2RewardCalculations.t.sol +++ b/test/foundry/unit/StakingRewardsV2/StakingV2RewardCalculations.t.sol @@ -20,10 +20,10 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { fundAccountAndStakeV2(user1, initialStake); // get initial rewards - uint256 rewards = rewardEscrowV2.escrowedBalanceOf(user1); + uint256 balance = kwenta.balanceOf(user1); uint256 rewardsUsdc = usdc.balanceOf(user1); // assert initial rewards are 0 - assertEq(rewards, 0); + assertEq(balance, 0); assertEq(rewardsUsdc, 0); // send in 604800 (1 week) of rewards - (using 1 week for round numbers) @@ -49,9 +49,9 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { uint256 expectedRewards = 1 weeks; // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); + assertEq(balance, expectedRewards); rewardsUsdc = usdc.balanceOf(user1); - assertEq(rewards, expectedRewards); assertEq(rewardsUsdc, expectedRewards); // send in another 604800 (1 week) of rewards @@ -64,11 +64,11 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { getStakingRewardsV2(user1); // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); rewardsUsdc = usdc.balanceOf(user1); // we exect the same amount of rewards again as this week was exactly the same as the previous one uint256 numberOfPeriods = 2; - assertEq(rewards, expectedRewards * numberOfPeriods); + assertEq(balance, expectedRewards * numberOfPeriods); assertEq(rewardsUsdc, expectedRewards * numberOfPeriods); } @@ -91,11 +91,11 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { // user1 earns 100% of rewards fundAccountAndStakeV2(user1, initialStake); - // get initial rewards - uint256 rewards = rewardEscrowV2.escrowedBalanceOf(user1); + // get initial balance + uint256 balance = kwenta.balanceOf(user1); uint256 rewardsUsdc = usdc.balanceOf(user1); - // assert initial rewards are 0 - assertEq(rewards, 0); + // assert initial balance is 0 (everything is staked and rewards are 0) + assertEq(balance, 0); assertEq(rewardsUsdc, 0); // calculate expected reward @@ -112,9 +112,9 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { getStakingRewardsV2(user1); // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); rewardsUsdc = usdc.balanceOf(user1); - assertEq(rewards, expectedRewards); + assertEq(balance, expectedRewards); assertEq(rewardsUsdc, expectedUsdcRewards); // move forward to the end of the rewards period @@ -129,9 +129,9 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { getStakingRewardsV2(user1); // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); rewardsUsdc = usdc.balanceOf(user1); - assertEq(rewards, expectedRewards); + assertEq(balance, expectedRewards); assertEq(rewardsUsdc, expectedUsdcRewards); } @@ -160,11 +160,11 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { // user1 earns 100% of rewards fundAccountAndStakeV2(user1, initialStake); - // get initial rewards - uint256 rewards = rewardEscrowV2.escrowedBalanceOf(user1); + // get initial balance + uint256 balance = kwenta.balanceOf(user1); uint256 rewardsUsdc = usdc.balanceOf(user1); - // assert initial rewards are 0 - assertEq(rewards, 0); + // assert initial balance is 0 (everything is staked and rewards are 0) + assertEq(balance, 0); assertEq(rewardsUsdc, 0); // calculate expected reward @@ -181,10 +181,10 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { getStakingRewardsV2(user1); // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); + assertEq(balance, expectedRewards); rewardsUsdc = usdc.balanceOf(user1); - assertEq(rewards, expectedRewards); - // assertEq(rewardsUsdc, expectedUsdcRewards); + assertEq(rewardsUsdc, expectedUsdcRewards); // move forward to the end of the rewards period jumpToEndOfRewardsPeriod(waitTime); @@ -202,9 +202,9 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { getStakingRewardsV2(user5); // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); + assertEq(balance, expectedRewards); rewardsUsdc = usdc.balanceOf(user1); - assertEq(rewards, expectedRewards); assertApproxEqAbs(rewardsUsdc, expectedUsdcRewards, 10); } @@ -224,11 +224,11 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { // user1 earns 100% of rewards fundAccountAndStakeV2(user1, initialStake); - // get initial rewards - uint256 rewards = rewardEscrowV2.escrowedBalanceOf(user1); + // get initial balance + uint256 balance = kwenta.balanceOf(user1); uint256 rewardsUsdc = usdc.balanceOf(user1); - // assert initial rewards are 0 - assertEq(rewards, 0); + // assert initial balance is 0 (everything is staked and rewards are 0) + assertEq(balance, 0); assertEq(rewardsUsdc, 0); // calculate expected reward @@ -245,9 +245,9 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { getStakingRewardsV2(user1); // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); + assertEq(balance, expectedRewards); rewardsUsdc = usdc.balanceOf(user1); - assertEq(rewards, expectedRewards); assertEq(rewardsUsdc, expectedUsdcRewards); // move forward to the end of the rewards period @@ -269,9 +269,9 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { getStakingRewardsV2(user1); // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); + assertEq(balance, expectedRewards); rewardsUsdc = usdc.balanceOf(user1); - assertEq(rewards, expectedRewards); assertApproxEqAbs(rewardsUsdc, expectedUsdcRewards, 10); } @@ -291,11 +291,11 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { // user1 earns 100% of rewards fundAccountAndStakeV2(user1, initialStake); - // get initial rewards - uint256 rewards = rewardEscrowV2.escrowedBalanceOf(user1); + // get initial balance + uint256 balance = kwenta.balanceOf(user1); uint256 rewardsUsdc = usdc.balanceOf(user1); - // assert initial rewards are 0 - assertEq(rewards, 0); + // assert initial balance is 0 (everything is staked and rewards are 0) + assertEq(balance, 0); assertEq(rewardsUsdc, 0); // calculate expected reward @@ -312,9 +312,9 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { getStakingRewardsV2(user1); // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); + assertEq(balance, expectedRewards); rewardsUsdc = usdc.balanceOf(user1); - assertEq(rewards, expectedRewards); assertEq(rewardsUsdc, expectedUsdcRewards); // move forward to the end of the rewards period @@ -336,9 +336,9 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { getStakingRewardsV2(user1); // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); + assertEq(balance, expectedRewards); rewardsUsdc = usdc.balanceOf(user1); - assertEq(rewards, expectedRewards); assertApproxEqAbs(rewardsUsdc, expectedUsdcRewards, 10); // move forward to the end of the rewards period @@ -360,9 +360,9 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { getStakingRewardsV2(user1); // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); + assertEq(balance, expectedRewards); rewardsUsdc = usdc.balanceOf(user1); - assertEq(rewards, expectedRewards); assertApproxEqAbs(rewardsUsdc, expectedUsdcRewards, 10); } @@ -384,11 +384,11 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { // user1 earns 100% of rewards fundAccountAndStakeV2(user1, initialStake); - // get initial rewards - uint256 rewards = rewardEscrowV2.escrowedBalanceOf(user1); + // get initial balance + uint256 balance = kwenta.balanceOf(user1); uint256 rewardsUsdc = usdc.balanceOf(user1); - // assert initial rewards are 0 - assertEq(rewards, 0); + // assert initial balance is 0 (everything is staked and rewards are 0) + assertEq(balance, 0); assertEq(rewardsUsdc, 0); // calculate expected reward @@ -405,9 +405,9 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { getStakingRewardsV2(user1); // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); + assertEq(balance, expectedRewards); rewardsUsdc = usdc.balanceOf(user1); - assertEq(rewards, expectedRewards); assertEq(rewardsUsdc, expectedUsdcRewards); for (uint256 i = 0; i < numberOfRounds; i++) { @@ -430,9 +430,9 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { getStakingRewardsV2(user1); // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); + assertEq(balance, expectedRewards); rewardsUsdc = usdc.balanceOf(user1); - assertEq(rewards, expectedRewards); assertApproxEqAbs(rewardsUsdc, expectedUsdcRewards, 10); } } @@ -463,11 +463,11 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { // user1 earns 100% of rewards fundAccountAndStakeV2(user1, initialStake); - // get initial rewards - uint256 rewards = rewardEscrowV2.escrowedBalanceOf(user1); + // get initial balance + uint256 balance = kwenta.balanceOf(user1); uint256 rewardsUsdc = usdc.balanceOf(user1); - // assert initial rewards are 0 - assertEq(rewards, 0); + // assert initial balance is 0 (everything is staked and rewards are 0) + assertEq(balance, 0); assertEq(rewardsUsdc, 0); // calculate expected reward @@ -484,9 +484,9 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { getStakingRewardsV2(user1); // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); + assertEq(balance, expectedRewards); rewardsUsdc = usdc.balanceOf(user1); - assertEq(rewards, expectedRewards); assertEq(rewardsUsdc, expectedUsdcRewards); for (uint256 i = 0; i < numberOfRounds; i++) { @@ -513,10 +513,10 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { getStakingRewardsV2(user1); // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); + assertEq(balance, expectedRewards); rewardsUsdc = usdc.balanceOf(user1); - assertEq(rewards, expectedRewards); - assertApproxEqAbs(rewardsUsdc, expectedUsdcRewards, 10); + assertApproxEqAbs(rewardsUsdc, expectedUsdcRewards, 50); } } @@ -529,11 +529,11 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { // user1 earns 100% of rewards fundAccountAndStakeV2(user1, initialStake); - // get initial rewards - uint256 rewards = rewardEscrowV2.escrowedBalanceOf(user1); + // get initial balance + uint256 balance = kwenta.balanceOf(user1); uint256 rewardsUsdc = usdc.balanceOf(user1); - // assert initial rewards are 0 - assertEq(rewards, 0); + // assert initial balance is 0 (everything is staked and rewards are 0) + assertEq(balance, 0); assertEq(rewardsUsdc, 0); // send in 604800 (1 week) of rewards - (using 1 week for round numbers) @@ -559,9 +559,9 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { uint256 expectedRewards = 1 weeks / 2; // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); + assertEq(balance, expectedRewards); rewardsUsdc = usdc.balanceOf(user1); - assertEq(rewards, expectedRewards); assertEq(rewardsUsdc, expectedRewards); // fast forward 0.5 weeks - to the end of this period @@ -571,10 +571,10 @@ contract StakingV2RewardCalculationTests is DefaultStakingV2Setup { getStakingRewardsV2(user1); // check rewards - rewards = rewardEscrowV2.escrowedBalanceOf(user1); + balance = kwenta.balanceOf(user1); rewardsUsdc = usdc.balanceOf(user1); // we exect to claim the other half of this weeks rewards - assertEq(rewards, expectedRewards * 2); + assertEq(balance, expectedRewards * 2); assertEq(rewardsUsdc, expectedRewards * 2); } } diff --git a/test/foundry/utils/helpers/EscrowMigratorTestHelpers.t.sol b/test/foundry/utils/helpers/EscrowMigratorTestHelpers.t.sol index ad9b48b55..1f7eb9e99 100644 --- a/test/foundry/utils/helpers/EscrowMigratorTestHelpers.t.sol +++ b/test/foundry/utils/helpers/EscrowMigratorTestHelpers.t.sol @@ -504,14 +504,9 @@ contract EscrowMigratorTestHelpers is StakingTestHelpers { assertEq(earlyVestingFee, 90); assertEq(escrowAmount, registeredEscrowAmount); - uint256 cooldown = stakingRewardsV2.cooldownPeriod(); - if (registeredDuration < cooldown) { - assertEq(duration, cooldown); - assertEq(endTime, registeredEndTime - registeredDuration + cooldown); - } else { - assertEq(duration, registeredDuration); - assertEq(endTime, registeredEndTime); - } + assertEq(duration, registeredDuration); + assertEq(endTime, registeredEndTime); + } function checkEntryAfterStepThree(address account, uint256 i, uint256 entryID) diff --git a/test/foundry/utils/helpers/StakingTestHelpers.t.sol b/test/foundry/utils/helpers/StakingTestHelpers.t.sol index ebaf12b42..ca538d4be 100644 --- a/test/foundry/utils/helpers/StakingTestHelpers.t.sol +++ b/test/foundry/utils/helpers/StakingTestHelpers.t.sol @@ -230,16 +230,16 @@ contract StakingTestHelpers is StakingV2Setup { stakingRewardsV2.stakeEscrow(_amount); } + function unstakeEscrowedFundsAdminV2(address _account, uint256 _amount) internal { + vm.prank(address(rewardEscrowV2)); + stakingRewardsV2.unstakeEscrowAdmin(_account, _amount); + } + function unstakeEscrowedFundsV2(address _account, uint256 _amount) internal { vm.prank(_account); stakingRewardsV2.unstakeEscrow(_amount); } - function unstakeEscrowSkipCooldownFundsV2(address _account, uint256 _amount) internal { - vm.prank(address(rewardEscrowV2)); - stakingRewardsV2.unstakeEscrowSkipCooldown(_account, _amount); - } - function bulkCreateV1EscrowEntries(address _account, uint256 _amount, uint256 num) internal { vm.startPrank(treasury); kwenta.approve(address(rewardEscrowV1), _amount * num); diff --git a/test/foundry/utils/setup/StakingV2Setup.t.sol b/test/foundry/utils/setup/StakingV2Setup.t.sol index 515bc840b..c0df1084e 100644 --- a/test/foundry/utils/setup/StakingV2Setup.t.sol +++ b/test/foundry/utils/setup/StakingV2Setup.t.sol @@ -21,6 +21,7 @@ contract StakingV2Setup is StakingV1Setup { event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); event OperatorApproved(address owner, address operator, bool approved); event RewardPaid(address indexed account, uint256 reward); + event Staked(address indexed user, uint256 amount); event EscrowStaked(address indexed user, uint256 amount); event Vested(address indexed beneficiary, uint256 value); event VestingEntryCreated(