Skip to content

Commit fce907d

Browse files
committed
chore(protocol-contracts): revert if diff is null
1 parent 8868f62 commit fce907d

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

protocol-contracts/staking/contracts/OperatorStaking.sol

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ contract OperatorStaking is ERC1363Upgradeable, ReentrancyGuardTransient, UUPSUp
7676
error InvalidController();
7777

7878
/// @dev Thrown when liquid asset balance is insufficient to cover pending redemptions in {stakeExcess}.
79-
error InsufficientLiquidBalance(uint256 liquidBalance, uint256 assetsPendingRedemption);
79+
error NoExcessBalance(uint256 liquidBalance, uint256 assetsPendingRedemption);
8080

8181
modifier onlyOwner() {
8282
require(msg.sender == owner(), CallerNotProtocolStakingOwner(msg.sender));
@@ -242,17 +242,15 @@ contract OperatorStaking is ERC1363Upgradeable, ReentrancyGuardTransient, UUPSUp
242242
*
243243
* NOTE: Excess tokens will be in the `OperatorStaking` contract the operator is slashed
244244
* during a redemption flow or if donations are made to it. Anyone can call this function to
245-
* restake those tokens.
245+
* restake those tokens. This function will revert if the liquid balance is less than or equal
246+
* to the amount of assets in pending redemption .
246247
*/
247248
function stakeExcess() public virtual {
248249
ProtocolStaking protocolStaking_ = protocolStaking();
249250
protocolStaking_.release(address(this));
250251
uint256 liquidBalance = IERC20(asset()).balanceOf(address(this));
251252
uint256 assetsPendingRedemption = previewRedeem(totalSharesInRedemption());
252-
require(
253-
liquidBalance >= assetsPendingRedemption,
254-
InsufficientLiquidBalance(liquidBalance, assetsPendingRedemption)
255-
);
253+
require(liquidBalance > assetsPendingRedemption, NoExcessBalance(liquidBalance, assetsPendingRedemption));
256254
uint256 amountToRestake = liquidBalance - assetsPendingRedemption;
257255
protocolStaking_.stake(amountToRestake);
258256
}

protocol-contracts/staking/test/OperatorStaking.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,19 +415,19 @@ describe('OperatorStaking', function () {
415415
.withArgs(this.mock, this.protocolStaking, restakeAmount);
416416
});
417417

418-
it('should revert with InsufficientLiquidBalance when liquid balance is less than pending redemptions', async function () {
418+
it('should revert with NoExcessBalance when liquid balance is less than pending redemptions', async function () {
419419
// Deposit and request redemption
420420
await this.mock.connect(this.delegator1).deposit(ethers.parseEther('10'), this.delegator1);
421421
await this.mock.connect(this.delegator1).requestRedeem(ethers.parseEther('5'), this.delegator1, this.delegator1);
422422

423-
// Slash staked balance to reduce available funds (slash remaining 5 ETH staked)
423+
// Slash staked balance to reduce available funds (slash 3 assets)
424424
await this.protocolStaking.slashWithdrawal(this.mock, ethers.parseEther('3'));
425425

426426
await timeIncreaseNoMine(60);
427427

428428
// Now liquid balance (after release) will be less than assets pending redemption
429429
// since slashing reduced the staked balance but pending redemption still expects original value
430-
await expect(this.mock.stakeExcess()).to.be.revertedWithCustomError(this.mock, 'InsufficientLiquidBalance');
430+
await expect(this.mock.stakeExcess()).to.be.revertedWithCustomError(this.mock, 'NoExcessBalance');
431431
});
432432
});
433433

0 commit comments

Comments
 (0)