Skip to content

Commit

Permalink
remove rewards on ban
Browse files Browse the repository at this point in the history
  • Loading branch information
SamBorisov committed Nov 21, 2024
1 parent a29d829 commit affac9d
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion contracts/HydraChain/modules/Inspector/IInspector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface IInspector {
error NoBanSubject();
error NoInitiateBanSubject();
error BanAlreadyInitiated();
error NoBanInititated();
error NoBanInitiated();

/**
* @notice Set the penalty amount for the banned validators
Expand Down
2 changes: 1 addition & 1 deletion contracts/HydraChain/modules/Inspector/Inspector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ abstract contract Inspector is IInspector, ValidatorManager {
*/
function terminateBanProcedure() external {
if (bansInitiated[msg.sender] == 0) {
revert NoBanInititated();
revert NoBanInitiated();
}

bansInitiated[msg.sender] = 0;
Expand Down
2 changes: 2 additions & 0 deletions contracts/HydraStaking/HydraStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ contract HydraStaking is
// but only the leftForStaker will be automatically requested,
// so we have to set the unstake amount - leftForStaker as liquidity debt that must be paid as well
liquidityDebts[staker] += (unstakeAmount - leftForStaker).toInt256Safe();
// the generated rewards for the staker must be taken (if is active position, rewards will be already taken)
stakingRewards[staker].taken = stakingRewards[staker].total;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ abstract contract VestedStaking is IVestedStaking, Staking, Vesting {

if (stakeLeft == 0) {
// if position is closed when active, we delete all the vesting data
// that way allowing the user to open new position for the same staker with the same vesting manager
delete vestedStakingPositions[account];
}

Expand Down
4 changes: 2 additions & 2 deletions docs/HydraChain/HydraChain.md
Original file line number Diff line number Diff line change
Expand Up @@ -1553,10 +1553,10 @@ error MustBeWhitelisted()



### NoBanInititated
### NoBanInitiated

```solidity
error NoBanInititated()
error NoBanInitiated()
```


Expand Down
4 changes: 2 additions & 2 deletions docs/HydraChain/IHydraChain.md
Original file line number Diff line number Diff line change
Expand Up @@ -685,10 +685,10 @@ error MaxValidatorsReached()



### NoBanInititated
### NoBanInitiated

```solidity
error NoBanInititated()
error NoBanInitiated()
```


Expand Down
4 changes: 2 additions & 2 deletions docs/HydraChain/modules/Inspector/IInspector.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ error BanAlreadyInitiated()



### NoBanInititated
### NoBanInitiated

```solidity
error NoBanInititated()
error NoBanInitiated()
```


Expand Down
4 changes: 2 additions & 2 deletions docs/HydraChain/modules/Inspector/Inspector.md
Original file line number Diff line number Diff line change
Expand Up @@ -1090,10 +1090,10 @@ error MustBeWhitelisted()



### NoBanInititated
### NoBanInitiated

```solidity
error NoBanInititated()
error NoBanInitiated()
```


Expand Down
18 changes: 17 additions & 1 deletion test/HydraChain/Inspector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,21 @@ export function RunInspectorTests(): void {
const unstakePenalty = await calculatePenaltyByWeeks(VESTING_DURATION_WEEKS - 1, this.minStake);
const stakedAmount = await hydraStaking.stakeOf(staker.address);

// check the staking rewards before the ban
const rewardsBefore = await hydraStaking.stakingRewards(staker.address);
expect(rewardsBefore.total).to.be.not.equal(rewardsBefore.taken);

const stakedAmountAfterPenalty = stakedAmount.sub(unstakePenalty).sub(validatorBanPenalty);
const banTx = await systemHydraChain.connect(this.signers.governance).banValidator(staker.address);
const withdrawableAmount = await hydraStaking.leftToWithdrawPerStaker(staker.address);

await expect(banTx, "ValidatorBanned").to.emit(systemHydraChain, "ValidatorBanned").withArgs(staker.address);
expect(withdrawableAmount, "withdrawable").to.be.equal(stakedAmountAfterPenalty);

// the staker should not have claimable rewards after the ban
const rewards = await hydraStaking.stakingRewards(staker.address);
expect(rewards.total).to.be.equal(rewards.taken);

const liquidTokensThatMustBeCollected = (await hydraStaking.liquidityDebts(staker.address)).add(
withdrawableAmount
);
Expand Down Expand Up @@ -245,7 +253,7 @@ export function RunInspectorTests(): void {

await expect(hydraChain.connect(validatorToBan).terminateBanProcedure()).to.be.revertedWithCustomError(
hydraChain,
"NoBanInititated"
"NoBanInitiated"
);
});

Expand Down Expand Up @@ -276,12 +284,20 @@ export function RunInspectorTests(): void {

await time.increase(BAN_THRESHOLD);

// check the staking rewards before the ban
const rewardsBefore = await hydraStaking.stakingRewards(inBanProcessValidator.address);
expect(rewardsBefore.total).to.be.not.equal(rewardsBefore.taken);

const stakedAmount = await hydraStaking.stakeOf(inBanProcessValidator.address);
const banTx = await hydraChain.banValidator(inBanProcessValidator.address);
const reporterReward = await hydraChain.reporterReward();
const validatorBanPenalty = await hydraChain.validatorPenalty();
const withdrawableAmount = await hydraStaking.leftToWithdrawPerStaker(inBanProcessValidator.address);

// the staker should not have claimable rewards after the ban
const rewards = await hydraStaking.stakingRewards(inBanProcessValidator.address);
expect(rewards.total).to.be.equal(rewards.taken);

expect(await hydraStaking.stakeOf(inBanProcessValidator.address), "stakedOf").to.be.eq(0);
expect(withdrawableAmount, "withdrawableAmount").to.be.equal(
stakedAmount.sub(reporterReward).sub(validatorBanPenalty)
Expand Down

0 comments on commit affac9d

Please sign in to comment.