diff --git a/src/Staking.sol b/src/Staking.sol index d49e053..982d861 100644 --- a/src/Staking.sol +++ b/src/Staking.sol @@ -38,7 +38,7 @@ contract GhostStaking is IStaking, GhostAccessControlled { uint256 private _lastRebaseBlock; - mapping(address => bool) public locks; + mapping(address => bool) public unlocks; constructor( address _ftso, @@ -79,7 +79,7 @@ contract GhostStaking is IStaking, GhostAccessControlled { bool isRebase, bool isClaim ) external override returns (uint256 returnAmount) { - if (locks[to] && to != msg.sender) revert ExternalDepositsLocked(); + if (!unlocks[to] && to != msg.sender) revert ExternalDepositsLocked(); returnAmount = amount + rebase(); IERC20(ftso).safeTransferFrom(msg.sender, address(this), amount); @@ -94,7 +94,7 @@ contract GhostStaking is IStaking, GhostAccessControlled { } function claim(address to, bool isRebase) public override returns (uint256) { - if (locks[to] && to != msg.sender) revert ExternalDepositsLocked(); + if (!unlocks[to] && to != msg.sender) revert ExternalDepositsLocked(); uint256 claimedAmount = IGhostWarmup(warmup).claim(to, epoch.number); return _sendGhstBased(claimedAmount, to, isRebase); } @@ -104,7 +104,7 @@ contract GhostStaking is IStaking, GhostAccessControlled { uint256 amount, bool isRebase ) public override returns (uint256) { - if (locks[to] && to != msg.sender) revert ExternalDepositsLocked(); + if (!unlocks[to] && to != msg.sender) revert ExternalDepositsLocked(); uint256 claimedAmount = IGhostWarmup(warmup).claimByAmount(to, amount, epoch.number); return _sendGhstBased(claimedAmount, to, isRebase); } @@ -123,7 +123,7 @@ contract GhostStaking is IStaking, GhostAccessControlled { } function toggleLock() external override { - locks[msg.sender] = !locks[msg.sender]; + unlocks[msg.sender] = !unlocks[msg.sender]; } function unstake( @@ -260,9 +260,9 @@ contract GhostStaking is IStaking, GhostAccessControlled { } function warmupInfo(address who) external view returns (uint256, uint256, uint48, bool) { - bool lock = locks[who]; (uint256 deposit, uint256 payout, uint48 expiry) = IGhostWarmup(warmup).warmupInfo(who); - return (deposit, payout, expiry, lock); + bool matured = expiry > 0 && epoch.number >= expiry; + return (deposit, payout, expiry, matured); } function totalReserves() external override view returns (uint256) { diff --git a/src/types/NoteKeeper.sol b/src/types/NoteKeeper.sol index 8608312..4697fe3 100644 --- a/src/types/NoteKeeper.sol +++ b/src/types/NoteKeeper.sol @@ -25,7 +25,6 @@ abstract contract NoteKeeper is INoteKeeper { _GHST = IGHST(_ghstAddress); _STAKING = IStaking(_stakingAddress); _TREASURY = ITreasury(_treasuryAddress); - _STAKING.toggleLock(); } function addNote( diff --git a/test/bonding/BondDepositorty.t.sol b/test/bonding/BondDepositorty.t.sol index c0ca212..9f7e8c6 100644 --- a/test/bonding/BondDepositorty.t.sol +++ b/test/bonding/BondDepositorty.t.sol @@ -548,7 +548,7 @@ contract GhostBondDepositoryTest is Test { (, uint256 payout,, bool matured) = staking.warmupInfo(address(depository)); assertEq(ghst.balanceOf(address(depository)) > 0, true); assertEq(payout > 0, true); - assertEq(matured, true); + assertEq(matured, false); vm.prank(BOB); depository.forceRedeemAll(bytes32(0)); diff --git a/test/staking/Staking.t.sol b/test/staking/Staking.t.sol index 96eb086..bc7c377 100644 --- a/test/staking/Staking.t.sol +++ b/test/staking/Staking.t.sol @@ -179,11 +179,11 @@ contract StakingTest is Test { assertEq(ftso.balanceOf(ALICE), 0); assertApproxEqAbs(staking.supplyInWarmup(), rebased, 1); - (uint256 deposit, uint256 payout, uint48 expiry, bool lock) = staking.warmupInfo(ALICE); + (uint256 deposit, uint256 payout, uint48 expiry, bool matured) = staking.warmupInfo(ALICE); assertEq(deposit, AMOUNT); assertEq(payout, ghst.balanceTo(AMOUNT)); assertEq(expiry, 1); - assertEq(lock, false); + assertEq(matured, true); } function test_stake_emitsStakedEvent() public { @@ -227,15 +227,17 @@ contract StakingTest is Test { assertEq(ftso.balanceOf(ALICE), 0); assertApproxEqAbs(staking.supplyInWarmup(), rebased, 1); - (uint256 deposit, uint256 payout, uint48 expiry, bool lock) = staking.warmupInfo(ALICE); + (uint256 deposit, uint256 payout, uint48 expiry, bool matured) = staking.warmupInfo(ALICE); assertEq(deposit, AMOUNT); assertEq(payout, ghst.balanceTo(AMOUNT)); assertEq(expiry, 2); - assertEq(lock, false); + assertEq(matured, false); } function test_stake_allowsSelfDepositWhenNotLocked() public { _mintAndApprove(ALICE, AMOUNT); + vm.prank(BOB); + staking.toggleLock(); vm.prank(ALICE); staking.stake(AMOUNT, BOB, false, false); @@ -245,8 +247,6 @@ contract StakingTest is Test { function test_stake_disablesExternalDepositsWhenLocked() public { _mintAndApprove(ALICE, AMOUNT); - vm.prank(BOB); - staking.toggleLock(); vm.expectRevert(); vm.prank(ALICE); @@ -279,9 +279,6 @@ contract StakingTest is Test { _prepareAndRoll(ALICE, AMOUNT, false, false); assertEq(ghst.balanceOf(ALICE), 0); - vm.prank(ALICE); - staking.toggleLock(); - vm.expectRevert(); vm.prank(BOB); staking.claim(ALICE, false); @@ -290,6 +287,8 @@ contract StakingTest is Test { function test_claim_allowExternalClaimsWhenNotLocked() public { _prepareAndRoll(ALICE, AMOUNT, false, false); + vm.prank(ALICE); + staking.toggleLock(); assertEq(ghst.balanceOf(ALICE), 0); vm.prank(BOB);