Compare commits

..

4 Commits

6 changed files with 37 additions and 23 deletions

View File

@ -137,6 +137,15 @@ contract Gatekeeper is IGatekeeper, Weaver, ReentrancyGuard {
bool validSignature = Verifier.verifyGhost(call, px, rx, s);
if (!validSignature) revert BadSignature();
bytes4 selector = bytes4(call[:4]);
if (
selector != this.recall.selector &&
selector != this.rotate.selector &&
selector != this.govern.selector
) {
revert InvalidSelector();
}
(bool success,) = address(this).call(call);
if (!success) revert ExecutionReverted();

View File

@ -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,12 +79,14 @@ contract GhostStaking is IStaking, GhostAccessControlled {
bool isRebase,
bool isClaim
) external override returns (uint256 returnAmount) {
returnAmount = amount + rebase();
if (!unlocks[to] && to != msg.sender) revert ExternalDepositsLocked();
returnAmount = amount + this.rebase();
IERC20(ftso).safeTransferFrom(msg.sender, address(this), amount);
if (isClaim && warmupPeriod == 0) {
returnAmount = _sendStnkBased(returnAmount, to, isRebase);
} else {
if (locks[to] && to != msg.sender) revert ExternalDepositsLocked();
uint48 expiry = epoch.number + warmupPeriod;
IGhostWarmup(warmup).addToWarmup(returnAmount, to, expiry);
}
@ -92,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);
}
@ -102,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);
}
@ -121,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(
@ -130,12 +132,14 @@ contract GhostStaking is IStaking, GhostAccessControlled {
bool isTrigger,
bool isRebase
) external override returns (uint256) {
amount += isTrigger ? rebase() : 0;
uint256 extraAmount = isTrigger ? this.rebase() : 0;
if (isRebase) {
amount += extraAmount;
ISTNK(stnk).safeTransferFrom(msg.sender, address(this), amount);
} else {
IGHST(ghst).burn(msg.sender, amount);
amount = IGHST(ghst).balanceFrom(amount);
amount = IGHST(ghst).balanceFrom(amount) + extraAmount;
}
if (amount > IERC20(ftso).balanceOf(address(this))) revert InsufficientBalance();
@ -211,8 +215,10 @@ contract GhostStaking is IStaking, GhostAccessControlled {
if (distributor != address(0)) {
IDistributor(distributor).distribute();
if (msg.sender == address(this)) {
bounty = IDistributor(distributor).retrieveBounty();
}
}
uint256 balance = IERC20(ftso).balanceOf(address(this));
uint256 extra = ISTNK(stnk).circulatingSupply() + bounty;
@ -258,9 +264,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) {

View File

@ -8,6 +8,7 @@ interface IGatekeeper {
error BadSignature();
error NotGatekeeper();
error AlreadyExecuted();
error InvalidSelector();
error InvalidCalldata();
error InvalidPublicKey();
error NonExistentAmount();

View File

@ -25,7 +25,6 @@ abstract contract NoteKeeper is INoteKeeper {
_GHST = IGHST(_ghstAddress);
_STAKING = IStaking(_stakingAddress);
_TREASURY = ITreasury(_treasuryAddress);
_STAKING.toggleLock();
}
function addNote(

View File

@ -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));

View File

@ -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);
@ -577,7 +576,7 @@ contract StakingTest is Test {
(,,, uint256 distribute) = staking.epoch();
assertEq(distribute, postBounty);
assertEq(stnk.balanceOf(ALICE), postBounty);
assertEq(ftso.balanceOf(address(staking)), 2 * postBounty + bounty);
assertEq(ftso.balanceOf(address(staking)), 2 * postBounty);
}
function test_arbitraryAddressCouldNotAddGatekeeper(address someone, address maybeGatekeeper) public {