Skip to content

Commit

Permalink
custom error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanjay Yadav authored and Sanjay Yadav committed Dec 5, 2023
1 parent cca972e commit 77aef08
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
4 changes: 3 additions & 1 deletion contracts/OperatorRewardsCollector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ contract OperatorRewardsCollector is IOperatorRewardsCollector, AccessControlUpg
// If the liquidation is not repaid, check balance and then proceed with repayment
if (!operatorLiquidation.isRepaid) {
// Ensure that the balance is sufficient
require(balances[operator] >= operatorLiquidation.totalAmountInEth, 'Insufficient balance');
if (balances[operator] < operatorLiquidation.totalAmountInEth) {
revert InsufficientBalance();
}

// Repay the liquidation and update the operator's balance
sdUtilityPool.repayLiquidation(operator);
Expand Down
5 changes: 4 additions & 1 deletion contracts/SDIncentiveController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ contract SDIncentiveController is ISDIncentiveController, AccessControlUpgradeab
/// @param _staderConfig The address of the Stader configuration contract.
function initialize(address _admin, address _staderConfig) external initializer {
UtilLib.checkNonZeroAddress(_staderConfig);
UtilLib.checkNonZeroAddress(_admin);

staderConfig = IStaderConfig(_staderConfig);

Expand All @@ -55,7 +56,9 @@ contract SDIncentiveController is ISDIncentiveController, AccessControlUpgradeab
updateReward(account);

uint256 reward = rewards[account];
require(reward > 0, 'No rewards to claim.');
if (reward == 0) {
revert NoRewardsToClaim();
}
rewards[account] = 0;
IERC20(staderConfig.getStaderToken()).transfer(account, reward);

Expand Down
16 changes: 12 additions & 4 deletions contracts/SDUtilityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ contract SDUtilityPool is ISDUtilityPool, AccessControlUpgradeable, PausableUpgr
function liquidationCall(address account) external override {
UserData memory userData = getUserData(account);

require(userData.healthFactor <= 1, 'Not liquidatable');
if (userData.healthFactor > 1) {
revert NotLiquidatable();
}

accrueFee();
utilizerData[account].utilizeIndex = utilizeIndex;
Expand Down Expand Up @@ -395,9 +397,15 @@ contract SDUtilityPool is ISDUtilityPool, AccessControlUpgradeable, PausableUpgr
function claimLiquidation(uint256 index) external override {
OperatorLiquidation storage liquidation = liquidations[index];

require(liquidation.isRepaid == true, 'Not claimable');
require(liquidation.isClaimed == false, 'Already claimed');
require(liquidation.liquidator == msg.sender, 'Not liquidator');
if (!liquidation.isRepaid) {
revert NotClaimable();
}
if (liquidation.isClaimed) {
revert AlreadyClaimed();
}
if (liquidation.liquidator != msg.sender) {
revert NotLiquidator();
}

liquidation.isClaimed = true;

Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/IOperatorRewardsCollector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pragma solidity 0.8.16;

interface IOperatorRewardsCollector {
//errors
error InsufficientBalance();
// events
event UpdatedStaderConfig(address indexed staderConfig);
event Claimed(address indexed receiver, uint256 amount);
Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/ISDIncentiveController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pragma solidity 0.8.16;
import './IStaderConfig.sol';

interface ISDIncentiveController {
//errors
error NoRewardsToClaim();
// events
event UpdatedStaderConfig(address staderConfig);

Expand Down
4 changes: 4 additions & 0 deletions contracts/interfaces/ISDUtilityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ struct OperatorLiquidation {

interface ISDUtilityPool {
error InvalidInput();
error NotClaimable();
error AlreadyClaimed();
error NotLiquidator();
error NotLiquidatable();
error SDTransferFailed();
error CannotFindRequestId();
error SDUtilizeLimitReached();
Expand Down

0 comments on commit 77aef08

Please sign in to comment.