add stake and unstake events; tests included
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
parent
93b18e719d
commit
169cb516a1
@ -72,6 +72,7 @@ contract GhostStaking is IStaking, GhostAccessControlled {
|
|||||||
uint48 expiry = epoch.number + warmupPeriod;
|
uint48 expiry = epoch.number + warmupPeriod;
|
||||||
IGhostWarmup(warmup).addToWarmup(returnAmount, to, expiry);
|
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) {
|
function claim(address to, bool isRebase) public override returns (uint256 claimedAmount) {
|
||||||
@ -115,6 +116,7 @@ contract GhostStaking is IStaking, GhostAccessControlled {
|
|||||||
|
|
||||||
if (amount > IERC20(ftso).balanceOf(address(this))) revert InsufficientBalance();
|
if (amount > IERC20(ftso).balanceOf(address(this))) revert InsufficientBalance();
|
||||||
IERC20(ftso).safeTransfer(to, amount);
|
IERC20(ftso).safeTransfer(to, amount);
|
||||||
|
emit Unstaked(msg.sender, to, amount, isTrigger, isRebase);
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,22 @@ interface IStaking {
|
|||||||
error ExternalClaimsLocked();
|
error ExternalClaimsLocked();
|
||||||
error InsufficientBalance();
|
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 DistributorSet(address distributor);
|
||||||
event GatekeeperSet(address gatekeeper);
|
event GatekeeperSet(address gatekeeper);
|
||||||
event WarmupSet(uint256 warmup);
|
event WarmupSet(uint256 warmup);
|
||||||
|
|||||||
@ -46,6 +46,22 @@ contract StakingTest is Test {
|
|||||||
uint256 public constant AMOUNT = 69;
|
uint256 public constant AMOUNT = 69;
|
||||||
uint256 public constant BIG_AMOUNT = AMOUNT * 1e9;
|
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 DistributorSet(address distributor);
|
||||||
event WarmupSet(uint256 warmup);
|
event WarmupSet(uint256 warmup);
|
||||||
event Ghosted(bytes32 indexed receiver, uint256 indexed amount);
|
event Ghosted(bytes32 indexed receiver, uint256 indexed amount);
|
||||||
@ -149,6 +165,16 @@ contract StakingTest is Test {
|
|||||||
assertEq(lock, false);
|
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 {
|
function test_stake_exchangesFatsoToStinkyWhenClaimIsTrueAndRebasingIsTrue() public {
|
||||||
_mintAndApprove(ALICE, AMOUNT);
|
_mintAndApprove(ALICE, AMOUNT);
|
||||||
|
|
||||||
@ -298,6 +324,19 @@ contract StakingTest is Test {
|
|||||||
assertEq(staking.supplyInWarmup(), 0);
|
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 {
|
function test_unstake_canRedeemStinkyToFatso() public {
|
||||||
_prepareAndRoll(ALICE, AMOUNT, true, true);
|
_prepareAndRoll(ALICE, AMOUNT, true, true);
|
||||||
uint256 aliceBalance = stnk.balanceOf(ALICE);
|
uint256 aliceBalance = stnk.balanceOf(ALICE);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user