Skip to content

Commit

Permalink
renamed timestamp to endOfCooldown
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelvm5 committed Aug 26, 2024
1 parent f58a39a commit 634909e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
12 changes: 6 additions & 6 deletions src/contracts/extension/ERC4626StakeTokenUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ abstract contract ERC4626StakeTokenUpgradeable is
CooldownSnapshot memory cooldownSnapshot = $._stakerCooldown[owner];

if (
block.timestamp >= cooldownSnapshot.timestamp &&
block.timestamp - cooldownSnapshot.timestamp <= $._unstakeWindow
block.timestamp >= cooldownSnapshot.endOfCooldown &&
block.timestamp - cooldownSnapshot.endOfCooldown <= $._unstakeWindow
) {
return cooldownSnapshot.amount;
}
Expand Down Expand Up @@ -190,7 +190,7 @@ abstract contract ERC4626StakeTokenUpgradeable is

$._stakerCooldown[from] = CooldownSnapshot({
amount: amount.toUint224(),
timestamp: timeToUnlock
endOfCooldown: timeToUnlock
});

emit CooldownSet(from, amount, timeToUnlock);
Expand All @@ -216,7 +216,7 @@ abstract contract ERC4626StakeTokenUpgradeable is

// if cooldown was activated and user is trying to transfer/redeem tokens
// we don't take into account that cooldown could be already outdated
if (cooldownSnapshot.timestamp != 0) {
if (cooldownSnapshot.endOfCooldown != 0) {
if (to == address(0)) {
// `from` redeems tokens here
// reduce amount available for redeem in the future
Expand All @@ -236,10 +236,10 @@ abstract contract ERC4626StakeTokenUpgradeable is
if ($._stakerCooldown[from].amount != cooldownSnapshot.amount) {
if (cooldownSnapshot.amount == 0) {
// if user spend all balance or already redeem whole amount
cooldownSnapshot.timestamp = 0;
cooldownSnapshot.endOfCooldown = 0;
}
$._stakerCooldown[from] = cooldownSnapshot;
emit StakerCooldownChanged(from, cooldownSnapshot.amount, cooldownSnapshot.timestamp);
emit StakerCooldownChanged(from, cooldownSnapshot.amount, cooldownSnapshot.endOfCooldown);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/contracts/interfaces/IERC4626StakeToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface IERC4626StakeToken is IERC4626 {
/// @notice Amount of shares available to redeem
uint224 amount;
/// @notice Time to unlock funds for withdrawal
uint32 timestamp;
uint32 endOfCooldown;
}

struct SignatureParams {
Expand All @@ -17,8 +17,8 @@ interface IERC4626StakeToken is IERC4626 {
bytes32 s;
}

event CooldownSet(address indexed user, uint256 amount, uint256 timestamp);
event StakerCooldownChanged(address indexed user, uint256 amount, uint256 timestamp);
event CooldownSet(address indexed user, uint256 amount, uint256 endOfCooldown);
event StakerCooldownChanged(address indexed user, uint256 amount, uint256 endOfCooldown);

event Slashed(address indexed destination, uint256 amount);

Expand Down
24 changes: 12 additions & 12 deletions tests/Cooldown.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract CooldownTests is StakeTestBase {
stakeToken.cooldown();
IERC4626StakeToken.CooldownSnapshot memory snapshotBefore = stakeToken.getStakerCooldown(user);

assertEq(snapshotBefore.timestamp, block.timestamp + stakeToken.getCooldown());
assertEq(snapshotBefore.endOfCooldown, block.timestamp + stakeToken.getCooldown());
assertEq(snapshotBefore.amount, stakeToken.convertToShares(amountToStake));

skip(stakeToken.getCooldown());
Expand All @@ -28,7 +28,7 @@ contract CooldownTests is StakeTestBase {
IERC4626StakeToken.CooldownSnapshot memory snapshotAfter = stakeToken.getStakerCooldown(user);

assertEq(snapshotAfter.amount, stakeToken.convertToShares(amountToStake - amountToWithdraw));
assertEq(snapshotAfter.timestamp, snapshotBefore.timestamp);
assertEq(snapshotAfter.endOfCooldown, snapshotBefore.endOfCooldown);
}

function test_cooldownNoIncreaseInAmount(uint192 amountToStake, uint192 amountToTopUp) public {
Expand All @@ -49,10 +49,10 @@ contract CooldownTests is StakeTestBase {

IERC4626StakeToken.CooldownSnapshot memory snapshotAfter = stakeToken.getStakerCooldown(user);

assertEq(snapshotBefore.timestamp, snapshotAfter.timestamp);
assertEq(snapshotBefore.endOfCooldown, snapshotAfter.endOfCooldown);
assertEq(snapshotBefore.amount, snapshotAfter.amount);

assertEq(snapshotAfter.timestamp, block.timestamp + stakeToken.getCooldown());
assertEq(snapshotAfter.endOfCooldown, block.timestamp + stakeToken.getCooldown());
assertEq(snapshotAfter.amount, stakeToken.convertToShares(amountToStake));

_deposit(amountToTopUp, someone, someone);
Expand All @@ -65,10 +65,10 @@ contract CooldownTests is StakeTestBase {
IERC4626StakeToken.CooldownSnapshot memory snapshotAfterSecondTopUp = stakeToken
.getStakerCooldown(user);

assertEq(snapshotBefore.timestamp, snapshotAfterSecondTopUp.timestamp);
assertEq(snapshotBefore.endOfCooldown, snapshotAfterSecondTopUp.endOfCooldown);
assertEq(snapshotBefore.amount, snapshotAfterSecondTopUp.amount);

assertEq(snapshotAfterSecondTopUp.timestamp, block.timestamp + stakeToken.getCooldown());
assertEq(snapshotAfterSecondTopUp.endOfCooldown, block.timestamp + stakeToken.getCooldown());
assertEq(snapshotAfterSecondTopUp.amount, stakeToken.convertToShares(amountToStake));
}

Expand All @@ -86,14 +86,14 @@ contract CooldownTests is StakeTestBase {

IERC4626StakeToken.CooldownSnapshot memory snapshot1 = stakeToken.getStakerCooldown(user);

assertEq(snapshot0.timestamp, snapshot1.timestamp);
assertEq(snapshot0.endOfCooldown, snapshot1.endOfCooldown);
assertEq(snapshot0.amount, snapshot1.amount + sharesToTransfer);

stakeToken.transfer(someone, stakeToken.balanceOf(user));

IERC4626StakeToken.CooldownSnapshot memory snapshot2 = stakeToken.getStakerCooldown(user);

assertEq(snapshot2.timestamp, 0);
assertEq(snapshot2.endOfCooldown, 0);
assertEq(snapshot2.amount, 0);
}

Expand All @@ -113,14 +113,14 @@ contract CooldownTests is StakeTestBase {

IERC4626StakeToken.CooldownSnapshot memory snapshot1 = stakeToken.getStakerCooldown(user);

assertEq(snapshot0.timestamp, snapshot1.timestamp);
assertEq(snapshot0.endOfCooldown, snapshot1.endOfCooldown);
assertEq(snapshot0.amount, snapshot1.amount + sharesToRedeem);

stakeToken.redeem(stakeToken.balanceOf(user), user, user);

IERC4626StakeToken.CooldownSnapshot memory snapshot2 = stakeToken.getStakerCooldown(user);

assertEq(snapshot2.timestamp, 0);
assertEq(snapshot2.endOfCooldown, 0);
assertEq(snapshot2.amount, 0);
}

Expand Down Expand Up @@ -192,7 +192,7 @@ contract CooldownTests is StakeTestBase {

IERC4626StakeToken.CooldownSnapshot memory snapshotBefore = stakeToken.getStakerCooldown(user);

assertEq(snapshotBefore.timestamp, block.timestamp + stakeToken.getCooldown());
assertEq(snapshotBefore.endOfCooldown, block.timestamp + stakeToken.getCooldown());
assertEq(snapshotBefore.amount, stakeToken.convertToShares(amountToStake));

skip(stakeToken.getCooldown());
Expand All @@ -202,7 +202,7 @@ contract CooldownTests is StakeTestBase {
IERC4626StakeToken.CooldownSnapshot memory snapshotAfter = stakeToken.getStakerCooldown(user);

assertEq(snapshotAfter.amount + sharesToRedeem, snapshotBefore.amount);
assertEq(snapshotAfter.timestamp, snapshotBefore.timestamp);
assertEq(snapshotAfter.endOfCooldown, snapshotBefore.endOfCooldown);
}

function test_cooldownOnBehalfNotApproved(uint192 amountToStake) public {
Expand Down

0 comments on commit 634909e

Please sign in to comment.