From 1b7da259b3170e4e873751b9c825b3bd37aa1cd2 Mon Sep 17 00:00:00 2001 From: toshiSat <10103480+toshiSat@users.noreply.github.com> Date: Sat, 3 Sep 2022 10:44:14 -0600 Subject: [PATCH 1/2] don't allow stake for someone else when warmup exists --- src/contracts/Staking.sol | 5 +++++ test/stakingTest.ts | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/contracts/Staking.sol b/src/contracts/Staking.sol index cb27171..7d70503 100644 --- a/src/contracts/Staking.sol +++ b/src/contracts/Staking.sol @@ -439,6 +439,11 @@ contract Staking is OwnableUpgradeable, StakingStorage { // amount must be non zero require(_amount > 0, "Must have valid amount"); + if (warmUpPeriod > 0) { + // can't stake for someone else if contract is using warmUp period + require(_recipient == msg.sender, "Can't stake for someone else with warmup"); + } + uint256 yieldyTotalSupply = IYieldy(YIELDY_TOKEN).totalSupply(); require( yieldyTotalSupply + _amount <= totalSupplyLimit, diff --git a/test/stakingTest.ts b/test/stakingTest.ts index c9c8c15..2d717d1 100644 --- a/test/stakingTest.ts +++ b/test/stakingTest.ts @@ -566,6 +566,12 @@ describe("Staking", function () { const stakingAmount = transferAmount; const stakingTokenStaker1 = stakingToken.connect(staker1Signer as Signer); await stakingTokenStaker1.approve(staking.address, stakingAmount); + + // can't stake to other addresses with warmup period + await expect( + stakingStaker1.functions["stake(uint256,address)"](stakingAmount, staking.address) + ).to.be.revertedWith("Can't stake for someone else with warmup"); + await stakingStaker1.functions["stake(uint256)"](stakingAmount); // balance should still be zero, until we claim the rewardToken. From d729952a106364bad82b91058248c0ffdc6fa74d Mon Sep 17 00:00:00 2001 From: toshiSat <10103480+toshiSat@users.noreply.github.com> Date: Sat, 3 Sep 2022 10:51:46 -0600 Subject: [PATCH 2/2] lint --- test/stakingTest.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/stakingTest.ts b/test/stakingTest.ts index 2d717d1..6c6b81b 100644 --- a/test/stakingTest.ts +++ b/test/stakingTest.ts @@ -569,7 +569,10 @@ describe("Staking", function () { // can't stake to other addresses with warmup period await expect( - stakingStaker1.functions["stake(uint256,address)"](stakingAmount, staking.address) + stakingStaker1.functions["stake(uint256,address)"]( + stakingAmount, + staking.address + ) ).to.be.revertedWith("Can't stake for someone else with warmup"); await stakingStaker1.functions["stake(uint256)"](stakingAmount);