From 634909eeae29c9361214fd7be8a51c530e2da4ef Mon Sep 17 00:00:00 2001 From: pavelvm5 Date: Mon, 26 Aug 2024 19:06:37 +0500 Subject: [PATCH] renamed timestamp to endOfCooldown --- .../ERC4626StakeTokenUpgradeable.sol | 12 +++++----- .../interfaces/IERC4626StakeToken.sol | 6 ++--- tests/Cooldown.t.sol | 24 +++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/contracts/extension/ERC4626StakeTokenUpgradeable.sol b/src/contracts/extension/ERC4626StakeTokenUpgradeable.sol index e8addd8..61d982f 100644 --- a/src/contracts/extension/ERC4626StakeTokenUpgradeable.sol +++ b/src/contracts/extension/ERC4626StakeTokenUpgradeable.sol @@ -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; } @@ -190,7 +190,7 @@ abstract contract ERC4626StakeTokenUpgradeable is $._stakerCooldown[from] = CooldownSnapshot({ amount: amount.toUint224(), - timestamp: timeToUnlock + endOfCooldown: timeToUnlock }); emit CooldownSet(from, amount, timeToUnlock); @@ -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 @@ -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); } } } diff --git a/src/contracts/interfaces/IERC4626StakeToken.sol b/src/contracts/interfaces/IERC4626StakeToken.sol index 17d25f2..6521ffe 100644 --- a/src/contracts/interfaces/IERC4626StakeToken.sol +++ b/src/contracts/interfaces/IERC4626StakeToken.sol @@ -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 { @@ -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); diff --git a/tests/Cooldown.t.sol b/tests/Cooldown.t.sol index c1e3a4e..e02f6a8 100644 --- a/tests/Cooldown.t.sol +++ b/tests/Cooldown.t.sol @@ -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()); @@ -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 { @@ -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); @@ -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)); } @@ -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); } @@ -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); } @@ -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()); @@ -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 {