Skip to content

Commit

Permalink
Transfer disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
anajuliabit committed Jun 28, 2024
1 parent bd648b7 commit 0e6a410
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ The contracts are designed to be customizable, with adjustable parameters such a
1. The total amount of SHU tokens staked in the contract must be equal to the
total amount of SHU tokens staked by each keyper: `totalStaked = sum(stakes[keyper].amount)`.
2. On unstake, `keyperStake.timestamp + lockPeriod <= block.timestamp` if global `lockPeriod` is greater or equal to the stake lock period, otherwise `keyperStake.timestamp + keyperStake.lockPeriod <= block.timestamp`.
3. If `some(keyperStakes(keyper).length()) > 0` then `nextStakeId` != 0;
8 changes: 4 additions & 4 deletions src/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ contract Staking is ERC20VotesUpgradeable, Ownable2StepUpgradeable {
//////////////////////////////////////////////////////////////*/

/// @notice stores the metadata associated with a given stake
mapping(uint256 id => Stake) public stakes;
mapping(uint256 id => Stake _stake) public stakes;

// @notice stake ids belonging to a keyper
// Uses EnumerableMap
Expand Down Expand Up @@ -345,12 +345,12 @@ contract Staking is ERC20VotesUpgradeable, Ownable2StepUpgradeable {
// Prevents the keyper from claiming more than they should
uint256 maxWithdrawAmount = maxWithdraw(keyper);

// If the amount is greater than the max withdraw amount, the contract
// will transfer the maximum amount available not the requested amount
// If the amount is 0, claim all the rewards
if (maxWithdrawAmount <= amount || amount == 0) {
if (amount == 0) {
rewards = maxWithdrawAmount;
} else {
require(amount <= maxWithdrawAmount, WithdrawAmountTooHigh());

rewards = amount;
}

Expand Down
44 changes: 39 additions & 5 deletions test/Staking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ contract ViewFunctions is StakingTest {
address _depositor
) public {
vm.expectRevert(Staking.KeyperHasNoShares.selector);
uint256 maxWithdraw = staking.maxWithdraw(_depositor);
staking.maxWithdraw(_depositor);
}

function testFuzz_maxWithdrawDepositorHasLockedStakeNoRewards(
Expand All @@ -1348,7 +1348,7 @@ contract ViewFunctions is StakingTest {
_mintGovToken(_depositor, _amount);
_setKeyper(_depositor, true);

uint256 stakeId = _stake(_depositor, _amount);
_stake(_depositor, _amount);

uint256 maxWithdraw = staking.maxWithdraw(_depositor);
assertEq(maxWithdraw, 0, "Wrong max withdraw");
Expand All @@ -1369,7 +1369,7 @@ contract ViewFunctions is StakingTest {
_mintGovToken(_depositor1, _amount1);
_setKeyper(_depositor1, true);

uint256 stakeId = _stake(_depositor1, _amount1);
_stake(_depositor1, _amount1);

uint256 timestampBefore = vm.getBlockTimestamp();

Expand Down Expand Up @@ -1408,7 +1408,7 @@ contract ViewFunctions is StakingTest {
assertEq(maxWithdraw, 0, "Wrong max withdraw");
}

function testFuzz_convertToSharesNoSupply(uint256 assets) public {
function testFuzz_convertToSharesNoSupply(uint256 assets) public view {
assertEq(staking.convertToShares(assets), assets);
}

Expand All @@ -1428,7 +1428,7 @@ contract ViewFunctions is StakingTest {
assertEq(shares, _assets, "Wrong shares");
}

function testFuzz_convertToAssetsNoSupply(uint256 shares) public {
function testFuzz_convertToAssetsNoSupply(uint256 shares) public view {
assertEq(staking.convertToAssets(shares), shares);
}

Expand Down Expand Up @@ -1480,3 +1480,37 @@ contract ViewFunctions is StakingTest {
assertEq(stakeIds[1], stakeId2, "Wrong stake id");
}
}

contract Transfer is StakingTest {
function testFuzz_RevertWith_transferDisabled(
address _from,
address _to,
uint256 _amount
) public {
_amount = _boundToRealisticStake(_amount);

_mintGovToken(_from, _amount);
_setKeyper(_from, true);

_stake(_from, _amount);

vm.expectRevert(Staking.TransferDisabled.selector);
staking.transfer(_to, _amount);
}

function testFuzz_RevertWith_transferFromDisabled(
address _from,
address _to,
uint256 _amount
) public {
_amount = _boundToRealisticStake(_amount);

_mintGovToken(_from, _amount);
_setKeyper(_from, true);

_stake(_from, _amount);

vm.expectRevert(Staking.TransferDisabled.selector);
staking.transferFrom(_from, _to, _amount);
}
}

0 comments on commit 0e6a410

Please sign in to comment.