Compare commits

..

2 Commits

Author SHA1 Message Date
169cb516a1
add stake and unstake events; tests included
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
2026-04-05 21:29:21 +03:00
93b18e719d
deploy underlying warmup right inside the staking constructor
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
2026-03-27 16:17:25 +03:00
4 changed files with 60 additions and 13 deletions

View File

@ -52,6 +52,9 @@ contract GhostStaking is IStaking, GhostAccessControlled {
end: _firstEpochTime,
distribute: 0
});
GhostWarmup newWarmup = new GhostWarmup(_ghst);
warmup = address(newWarmup);
}
function stake(
@ -69,6 +72,7 @@ contract GhostStaking is IStaking, GhostAccessControlled {
uint48 expiry = epoch.number + warmupPeriod;
IGhostWarmup(warmup).addToWarmup(returnAmount, to, expiry);
}
emit Staked(msg.sender, to, amount, isRebase, isClaim);
}
function claim(address to, bool isRebase) public override returns (uint256 claimedAmount) {
@ -112,6 +116,7 @@ contract GhostStaking is IStaking, GhostAccessControlled {
if (amount > IERC20(ftso).balanceOf(address(this))) revert InsufficientBalance();
IERC20(ftso).safeTransfer(to, amount);
emit Unstaked(msg.sender, to, amount, isTrigger, isRebase);
return amount;
}
@ -180,10 +185,6 @@ contract GhostStaking is IStaking, GhostAccessControlled {
function setWarmupPeriod(uint256 _warmupPeriod) external onlyGovernor {
// forge-lint: disable-next-line(unsafe-typecast)
warmupPeriod = uint48(_warmupPeriod);
if (warmup == address(0)) {
GhostWarmup newWarmup = new GhostWarmup(ghst);
warmup = address(newWarmup);
}
emit WarmupSet(_warmupPeriod);
}
@ -197,9 +198,6 @@ contract GhostStaking is IStaking, GhostAccessControlled {
}
function supplyInWarmup() public view override returns (uint256) {
if (warmup == address(0)) {
return 0;
}
return IGHST(ghst).balanceFrom(IGhostWarmup(warmup).ghstInWarmup());
}

View File

@ -6,6 +6,22 @@ interface IStaking {
error ExternalClaimsLocked();
error InsufficientBalance();
event Staked(
address sender,
address receiver,
uint256 amount,
bool isRebase,
bool isClaim
);
event Unstaked(
address sender,
address receiver,
uint256 amount,
bool isTrigger,
bool isRebase
);
event DistributorSet(address distributor);
event GatekeeperSet(address gatekeeper);
event WarmupSet(uint256 warmup);

View File

@ -90,9 +90,6 @@ contract GhostBondDepositoryTest is Test {
);
vm.stopPrank();
vm.prank(GOVERNOR);
staking.setWarmupPeriod(0);
_createFirstBond();
}

View File

@ -46,6 +46,22 @@ contract StakingTest is Test {
uint256 public constant AMOUNT = 69;
uint256 public constant BIG_AMOUNT = AMOUNT * 1e9;
event Staked(
address sender,
address receiver,
uint256 amount,
bool isRebase,
bool isClaim
);
event Unstaked(
address sender,
address receiver,
uint256 amount,
bool isTrigger,
bool isRebase
);
event DistributorSet(address distributor);
event WarmupSet(uint256 warmup);
event Ghosted(bytes32 indexed receiver, uint256 indexed amount);
@ -76,9 +92,6 @@ contract StakingTest is Test {
gatekeeper = new Gatekeeper(address(staking), 0, 0, 0, 0, 0);
calculator = new GhostBondingCalculator(address(ftso), 1, 1);
vm.stopPrank();
vm.prank(GOVERNOR);
staking.setWarmupPeriod(0);
}
function test_correctAfterConstruction() public view {
@ -152,6 +165,16 @@ contract StakingTest is Test {
assertEq(lock, false);
}
function test_stake_emitsStakedEvent() public {
_mintAndApprove(ALICE, AMOUNT);
vm.expectEmit(true, true, true, false, address(staking));
emit Staked(ALICE, ALICE, AMOUNT, true, true);
vm.prank(ALICE);
staking.stake(AMOUNT, ALICE, true, true);
}
function test_stake_exchangesFatsoToStinkyWhenClaimIsTrueAndRebasingIsTrue() public {
_mintAndApprove(ALICE, AMOUNT);
@ -301,6 +324,19 @@ contract StakingTest is Test {
assertEq(staking.supplyInWarmup(), 0);
}
function test_unstake_emitsUnstakedEvent() public {
_prepareAndRoll(ALICE, AMOUNT, true, true);
uint256 aliceBalance = stnk.balanceOf(ALICE);
vm.startPrank(ALICE);
stnk.approve(address(staking), aliceBalance);
vm.expectEmit(true, true, true, false, address(staking));
emit Unstaked(ALICE, ALICE, aliceBalance, false, true);
staking.unstake(aliceBalance, ALICE, false, true);
vm.stopPrank();
}
function test_unstake_canRedeemStinkyToFatso() public {
_prepareAndRoll(ALICE, AMOUNT, true, true);
uint256 aliceBalance = stnk.balanceOf(ALICE);