Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SD utility pool #212

Merged
merged 122 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
b3e9567
basic utility pool structure
Nov 6, 2023
d8664c1
sdCollateral intergration with utilityPool
Nov 6, 2023
f47f2e1
Rename SDx.sol to SDX.sol
sanjay-staderlabs Nov 6, 2023
b7aee57
terminology change
Nov 7, 2023
0b2b4c0
SD Incentive Controller (#210)
dulguun-staderlabs Nov 7, 2023
eb88282
utilize flow
Nov 14, 2023
82cc1c8
origin pull
Nov 14, 2023
12bab11
dwlwgator withdraw flow
Nov 14, 2023
7d706b7
seperate function in node registry to utilze SD
Nov 16, 2023
ac24c13
view function to get latest data
Nov 17, 2023
28e52c7
Liquidation (#211)
dulguun-staderlabs Nov 17, 2023
cb26fe2
Add back comments
dulguun-staderlabs Nov 17, 2023
efcfa04
include pause functionality
Nov 17, 2023
d771bfb
origin pull
Nov 17, 2023
5ea300a
repay flow changes and comments
Nov 20, 2023
1dd59d2
Operator reward integration (#213)
dulguun-staderlabs Nov 23, 2023
28a5a64
Add PoolUtils
dulguun-staderlabs Nov 23, 2023
4fbc7ba
claimLiquidation
dulguun-staderlabs Nov 23, 2023
51d3796
Fix compile
dulguun-staderlabs Nov 28, 2023
26c1f4d
Fix claimFor
dulguun-staderlabs Nov 28, 2023
f614c56
Add liquidator data
dulguun-staderlabs Nov 30, 2023
dcb8182
review fixes
Dec 2, 2023
c6ecd53
merge origin feat/SD_Utility_Pool
Dec 2, 2023
adae26e
deposit SD reward as collateral changes
Dec 2, 2023
2850ec0
Fix compilation
dulguun-staderlabs Dec 3, 2023
70ccf89
Change function orders
dulguun-staderlabs Dec 3, 2023
d3008fc
Fix review
dulguun-staderlabs Dec 3, 2023
b8f4db4
Add exit operator
dulguun-staderlabs Dec 3, 2023
db1f400
deposit SD reward as collateral flow changes
Dec 4, 2023
9f03ab3
Fix review
dulguun-staderlabs Dec 4, 2023
cca972e
Use operatorUtilizedSDBalance
dulguun-staderlabs Dec 4, 2023
77aef08
custom error message
Dec 5, 2023
351df68
deploy script for utility pool
Dec 5, 2023
62d839b
Updates on incentiveController
dulguun-staderlabs Dec 6, 2023
df0a793
Add docs and checkers
dulguun-staderlabs Dec 6, 2023
bf4a1e8
fix claim function time cool down logic
Dec 7, 2023
38a95a9
Add withdrawable
dulguun-staderlabs Dec 7, 2023
55205d0
Merge branch 'feat/SD_Utility_Pool' of https://github.com/stader-labs…
dulguun-staderlabs Dec 7, 2023
4234681
rename function and variables
Dec 8, 2023
2427c9f
Add non-existent liquidation check
dulguun-staderlabs Dec 8, 2023
004b7d1
fix sdCollateral withdraw function
Dec 8, 2023
d0ceaac
Merge branch 'feat/SD_Utility_Pool' of https://github.com/stader-labs…
Dec 8, 2023
8360869
Fix claim logic
dulguun-staderlabs Dec 8, 2023
cf935da
refactor slash SD
Dec 9, 2023
d78e882
Merge branch 'feat/SD_Utility_Pool' of https://github.com/stader-labs…
Dec 9, 2023
450a8e6
whenNotPaused modifier
Dec 9, 2023
c6bfcc8
Claim rewards during requestWithdraw
dulguun-staderlabs Dec 9, 2023
c3ab55a
review fixes
Dec 10, 2023
4fc456c
Merge branch 'feat/SD_Utility_Pool' of https://github.com/stader-labs…
Dec 10, 2023
673663d
change in request withdraw logic
Dec 10, 2023
5b9be86
Review fix
dulguun-staderlabs Dec 10, 2023
713d962
Introduce weth
dulguun-staderlabs Dec 10, 2023
8cd59c6
introducing withdrawOnBehalf in SDCollateral
Dec 11, 2023
432f6ca
Merge branch 'feat/SD_Utility_Pool' of https://github.com/stader-labs…
Dec 11, 2023
7f7dfa6
Transfer back utilized SD
dulguun-staderlabs Dec 11, 2023
4b74a72
add getter in interface
Dec 11, 2023
d7c3381
Merge branch 'feat/SD_Utility_Pool' of https://github.com/stader-labs…
Dec 11, 2023
90e0b9d
incentiveController and addValidatorKey fix
Dec 14, 2023
5788efb
test case for utilze and delegate flow
Dec 22, 2023
79c2a86
referral Id for adding validator keys
Dec 24, 2023
7d38257
sdCollateral test cases
Jan 2, 2024
42bd2f7
SD token decimal adjust
dulguun-staderlabs Jan 3, 2024
e9cdab0
Multiply by DECIMAL
dulguun-staderlabs Jan 3, 2024
45200fa
Liquidation test
dulguun-staderlabs Jan 4, 2024
4abd088
Only manager role for certain functions
dulguun-staderlabs Jan 5, 2024
7421670
test fix
Jan 5, 2024
c93e196
Fix weth issue
dulguun-staderlabs Jan 5, 2024
e9251e7
Small fix and unit test
dulguun-staderlabs Jan 7, 2024
fe32591
Minimum reward amount
dulguun-staderlabs Jan 7, 2024
f79c803
Claim available amount
dulguun-staderlabs Jan 7, 2024
914d4bb
Lint test
dulguun-staderlabs Jan 7, 2024
0996dc2
Add start incentive later test
dulguun-staderlabs Jan 7, 2024
39339f7
SDP-06 fix
Jan 8, 2024
8dcc156
Merge branch 'feat/SD_Utility_Pool' of https://github.com/stader-labs…
Jan 8, 2024
a79ba4e
SDP-11 fix
Jan 8, 2024
e4a2bfe
Fix SDP-03
dulguun-staderlabs Jan 8, 2024
d66e714
SDP-02 fix
Jan 8, 2024
b69ad87
push back SDP-03 fix
Jan 8, 2024
b8ae94b
SDP-07 fix
sanjay-staderlabs Jan 9, 2024
773f584
SDP-17 fix
sanjay-staderlabs Jan 9, 2024
2a31470
Take initial _delegate into consideration
dulguun-staderlabs Jan 10, 2024
4d981f3
whenNotPaused test cases
sanjay-staderlabs Jan 10, 2024
d1a230a
Merge branch 'feat/SD_Utility_Pool' of https://github.com/stader-labs…
sanjay-staderlabs Jan 10, 2024
bed5ffb
comment fix
sanjay-staderlabs Jan 11, 2024
5e38f9b
Expand liquidation call tests
dulguun-staderlabs Jan 11, 2024
8fdcb9a
Update SDIncentiveController.t.sol
dulguun-staderlabs Jan 11, 2024
5a9504f
Separate claim and claimLiquidation
dulguun-staderlabs Jan 11, 2024
87c80cf
Add test
dulguun-staderlabs Jan 11, 2024
e8ed9b1
Quick fix
dulguun-staderlabs Jan 11, 2024
ced164f
Remove claimFor
dulguun-staderlabs Jan 11, 2024
45358bb
Fix test
dulguun-staderlabs Jan 12, 2024
6d75aa2
Lint and add tests
dulguun-staderlabs Jan 14, 2024
6b4870c
small change claim
dulguun-staderlabs Jan 14, 2024
834adc4
Add emit tests
dulguun-staderlabs Jan 14, 2024
b8cf0c1
Refactor test
dulguun-staderlabs Jan 14, 2024
f8fe3f8
add emit test
dulguun-staderlabs Jan 14, 2024
a0962b6
claim after liquidation
dulguun-staderlabs Jan 14, 2024
a0b411f
change initial delegate amount to 1 SD
sanjay-staderlabs Jan 15, 2024
e9bc3a9
Initialise risk config at initialize
dulguun-staderlabs Jan 15, 2024
85164c6
Internal function prefix with _
dulguun-staderlabs Jan 15, 2024
21ba418
renaming change
sanjay-staderlabs Jan 15, 2024
a876de8
Collateral in ETH and expose liquidationIndexByOperator
dulguun-staderlabs Jan 17, 2024
73514c3
rounding up interest in ETH
sanjay-staderlabs Jan 17, 2024
7efcb29
reward collector test fixed
sanjay-staderlabs Jan 17, 2024
5a5797f
foundry deploy script
sanjay-staderlabs Jan 17, 2024
9176358
minimum withdraw and delegate limits
sanjay-staderlabs Jan 18, 2024
10b4341
rounding up cTokenShare in requestWithdrawWithSD call
sanjay-staderlabs Jan 18, 2024
492073d
fix utilityPool with min delegate amount
sanjay-staderlabs Jan 18, 2024
559d4bc
add clearUtilizedPosition function
sanjay-staderlabs Jan 29, 2024
238519a
add totalUtilizedSD getter in interface
sanjay-staderlabs Jan 30, 2024
b59025c
clearing utilized position using withdrawOnBehalf
sanjay-staderlabs Jan 31, 2024
d652be5
optimize _transferBackUtilizedSD
sanjay-staderlabs Jan 31, 2024
7d90edb
handling of edge cases when nonTerminalKeys are 0
sanjay-staderlabs Feb 1, 2024
1469477
update interface
sanjay-staderlabs Feb 1, 2024
e8b4afc
add utilityPool deploy script
sanjay-staderlabs Feb 6, 2024
cfb81ce
introduce claimWithAmount function in rewardCollector
sanjay-staderlabs Feb 7, 2024
c0b3f9a
fix: only call withdraw if balance of nodeELVault greater than 0
sanjay-staderlabs Feb 7, 2024
5bb7c2d
updating operatorRewardsCollector Interface
sanjay-staderlabs Feb 20, 2024
b2ca94c
adding third party license file
sanjay-staderlabs Feb 28, 2024
a76a8e8
fix formatting of README
sanjay-staderlabs Feb 28, 2024
ffe585a
add title in License file
sanjay-staderlabs Feb 28, 2024
46462f4
formatting the title of License file
sanjay-staderlabs Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ lcov.info
# Foundry
cache_forge/
out/
broadcast



13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

Check failure on line 1 in README.md

View workflow job for this annotation

GitHub Actions / Prettier

README.md#L1

There are issues with this file's formatting, please run Prettier to fix the errors

# Overview

Expand Down Expand Up @@ -56,3 +56,16 @@
# Integration

Check the Integration guide [here](https://github.com/stader-labs/ethx/blob/mainnet_V0/INTEGRATION.md)

# Dependencies
This project incorporates code from the following external sources:
- Compound Labs, Inc. (licensed under the BSD-3-Clause License)

- Ben Hauser (licensed under the MIT License)

The borrowed code contributes to 'SDUtilityPool.sol for computing fee, utilizer balance and exchange rate for a C-token based model' and 'SDIncentiveController.sol for computing incentivize rewards to the delegator of UtilityPool' respectively. For further details on the specific code sections and their respective licenses, please refer to the Third-Party Licenses file.

Link to Third-Party Licenses:

[THIRD-PARTY-LICENSES.md](https://github.com/stader-labs/ethx/blob/mainnet_V0/THIRD-PARTY-LICENSES.md)

82 changes: 82 additions & 0 deletions THIRD-PARTY-LICENSES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
THIRD PARTY LICENSES

Check failure on line 1 in THIRD-PARTY-LICENSES.md

View workflow job for this annotation

GitHub Actions / Prettier

THIRD-PARTY-LICENSES.md#L1

There are issues with this file's formatting, please run Prettier to fix the errors

Compound Code (BSD-3-Clause License)

This project incorporates portions of code originally developed by Compound Labs, Inc. and
licensed under the BSD-3-Clause License ("BSD-3-Clause"). The full text of the BSD-3-Clause
License is included below for your reference:

Copyright (c) 2020 Compound Labs, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.

- Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.

- Neither the name of the copyright holder nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior written
permission.


DISCLAIMER:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The following sections of this project codebase are derived from the Compound code:

contracts/SDUtilityPool.sol - accrueFee(), utilizerBalanceCurrent(address account),
utilizerBalanceStored(address account), _utilizerBalanceStoredInternal(address account),
exchangeRateCurrent(),exchangeRateStored(), _exchangeRateStored().

These are the logic to compute the rewards, compute utilizer balance and
exchangeRate computation for C-token based model.

Curvefi Code (MIT License)

This project incorporates portions of code originally developed by Ben Hauser and licensed
under the MIT License. The full text of the MIT License is included below for your reference:

MIT License

Copyright (c) 2020 Ben Hauser

Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to
do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Specific Code Attribution:

The following sections of this project codebase are derived from the Curvefi code:

contracts/SDIncentiveController.sol - updateRewardForAccount(address account),
rewardPerToken() and earned(address account).

These are mainly the logic for storing and computing user incentivize rewards.
172 changes: 166 additions & 6 deletions contracts/OperatorRewardsCollector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@ pragma solidity 0.8.16;

import './library/UtilLib.sol';

import './interfaces/INodeRegistry.sol';
import './interfaces/INodeELRewardVault.sol';
import './interfaces/IPermissionlessNodeRegistry.sol';
import './interfaces/IOperatorRewardsCollector.sol';
import './interfaces/IStaderConfig.sol';
import './interfaces/ISDUtilityPool.sol';
import './interfaces/SDCollateral/ISDCollateral.sol';
import './interfaces/IWETH.sol';
import '../contracts/interfaces/IStaderOracle.sol';

import '@openzeppelin/contracts/utils/math/Math.sol';
import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';

contract OperatorRewardsCollector is IOperatorRewardsCollector, AccessControlUpgradeable {
IStaderConfig public staderConfig;

mapping(address => uint256) public balances;

IWETH public weth;

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
Expand All @@ -36,19 +46,169 @@ contract OperatorRewardsCollector is IOperatorRewardsCollector, AccessControlUpg
emit DepositedFor(msg.sender, _receiver, msg.value);
}

/**
* @notice Claims payouts for an operator, repaying any outstanding liquidations and transferring any remaining balance to the operator's rewards address.
* @dev This function first checks for any unpaid liquidations for the operator and repays them if necessary. Then, it transfers any remaining balance to the operator's reward address.
*/
function claim() external {
address operator = msg.sender;
uint256 amount = balances[operator];
balances[operator] -= amount;
claimLiquidation(msg.sender);

address operatorRewardsAddr = UtilLib.getOperatorRewardAddress(msg.sender, staderConfig);
UtilLib.sendValue(operatorRewardsAddr, amount);
emit Claimed(operatorRewardsAddr, amount);
uint256 amount = balances[msg.sender] > withdrawableInEth(msg.sender)
? withdrawableInEth(msg.sender)
: balances[msg.sender];
_claim(msg.sender, amount);
}

/**
* @notice function to claim a given amount of ETH, this is done to make sure operator can claim
* any desired amount such that their health factor remains above 1
* @dev amount should not be more than the minimum of operator balance and withdrawableInEth after completing liquidation if any
* @param _amount amount of ETH to claim
*/
function claimWithAmount(uint256 _amount) external {
claimLiquidation(msg.sender);
_claim(msg.sender, _amount);
}

function claimLiquidation(address operator) public override {
_transferBackUtilizedSD(operator);
_completeLiquidationIfExists(operator);
}

function updateStaderConfig(address _staderConfig) external onlyRole(DEFAULT_ADMIN_ROLE) {
UtilLib.checkNonZeroAddress(_staderConfig);
staderConfig = IStaderConfig(_staderConfig);
emit UpdatedStaderConfig(_staderConfig);
}

function withdrawableInEth(address operator) public view override returns (uint256) {
ISDUtilityPool sdUtilityPool = ISDUtilityPool(staderConfig.getSDUtilityPool());
uint256 liquidationThreshold = sdUtilityPool.getLiquidationThreshold();
UserData memory userData = sdUtilityPool.getUserData(operator);
uint256 totalInterestAdjusted = (userData.totalInterestSD * 100) / liquidationThreshold;
uint256 sdPriceInETH = IStaderOracle(staderConfig.getStaderOracle()).getSDPriceInETH();

uint256 totalInterestAdjustedInEth = Math.ceilDiv(
(totalInterestAdjusted * sdPriceInETH),
staderConfig.getDecimals()
);

if (totalInterestAdjustedInEth > userData.totalCollateralInEth) return 0;
uint256 withdrawableAmountInEth = userData.totalCollateralInEth - totalInterestAdjustedInEth;

OperatorLiquidation memory operatorLiquidation = sdUtilityPool.getOperatorLiquidation(operator);
return
withdrawableAmountInEth > operatorLiquidation.totalAmountInEth
? withdrawableAmountInEth - operatorLiquidation.totalAmountInEth
: 0;
}

function updateWethAddress(address _weth) external onlyRole(DEFAULT_ADMIN_ROLE) {
UtilLib.checkNonZeroAddress(_weth);
weth = IWETH(_weth);
emit UpdatedWethAddress(_weth);
}

function getBalance(address operator) external view override returns (uint256) {
return balances[operator];
}

/**
* @notice Completes any pending liquidation for an operator if exists.
* @dev Internal function to handle liquidation completion.
* @param operator The operator whose liquidation needs to be checked.
*/
function _completeLiquidationIfExists(address operator) internal {
// Retrieve operator liquidation details
ISDUtilityPool sdUtilityPool = ISDUtilityPool(staderConfig.getSDUtilityPool());
OperatorLiquidation memory operatorLiquidation = sdUtilityPool.getOperatorLiquidation(operator);

// If the liquidation is not repaid, check balance and then proceed with repayment
if (!operatorLiquidation.isRepaid && operatorLiquidation.totalAmountInEth > 0) {
(uint8 poolId, uint256 operatorId, uint256 nonTerminalKeys) = ISDCollateral(staderConfig.getSDCollateral())
.getOperatorInfo(operator);
// Ensure that the balance is sufficient
if (balances[operator] < operatorLiquidation.totalAmountInEth && nonTerminalKeys > 0) {
revert InsufficientBalance();
}
address permissionlessNodeRegistry = staderConfig.getPermissionlessNodeRegistry();
if (INodeRegistry(permissionlessNodeRegistry).POOL_ID() == poolId) {
address nodeELVault = IPermissionlessNodeRegistry(permissionlessNodeRegistry)
.nodeELRewardVaultByOperatorId(operatorId);
if (nodeELVault.balance > 0) {
INodeELRewardVault(nodeELVault).withdraw();
}
}
if (balances[operator] < operatorLiquidation.totalAmountInEth) {
uint256 wETHDeposit = Math.min(
balances[operator],
operatorLiquidation.totalAmountInEth - operatorLiquidation.totalFeeInEth
);

weth.deposit{value: wETHDeposit}();
if (weth.transferFrom(address(this), operatorLiquidation.liquidator, wETHDeposit) == false)
revert WethTransferFailed();
balances[operator] -= wETHDeposit;

uint256 protocolFee = Math.min(operatorLiquidation.totalFeeInEth, balances[operator]);
UtilLib.sendValue(staderConfig.getStaderTreasury(), protocolFee);

balances[operator] -= protocolFee;
sdUtilityPool.completeLiquidation(operator);
} else {
// Transfer WETH to liquidator and ETH to treasury
weth.deposit{value: operatorLiquidation.totalAmountInEth - operatorLiquidation.totalFeeInEth}();
if (
weth.transferFrom(
address(this),
operatorLiquidation.liquidator,
operatorLiquidation.totalAmountInEth - operatorLiquidation.totalFeeInEth
) == false
) revert WethTransferFailed();
UtilLib.sendValue(staderConfig.getStaderTreasury(), operatorLiquidation.totalFeeInEth);

sdUtilityPool.completeLiquidation(operator);
balances[operator] -= operatorLiquidation.totalAmountInEth;
}
}
}

/**
* @notice Internal function to claim a specified amount for an operator.
* @dev Deducts the amount from the operator's balance and transfers it to their rewards address.
* It also checks if the claiming amount does not exceed the withdrawable limit or the operator's balance.
* @param operator The address of the operator claiming the amount.
* @param amount The amount to be claimed.
*/
function _claim(address operator, uint256 amount) internal {
uint256 maxWithdrawableInEth = withdrawableInEth(operator);

if (amount > maxWithdrawableInEth || amount > balances[operator]) revert InsufficientBalance();

balances[operator] -= amount;

// If there's an amount to send, transfer it to the operator's rewards address
if (amount > 0) {
address rewardsAddress = UtilLib.getOperatorRewardAddress(operator, staderConfig);
UtilLib.sendValue(rewardsAddress, amount);
emit Claimed(rewardsAddress, amount);
}
}

/**
* When the operator has no remaining active keys, transfer back the utilized SD to the operator.
* @param operator The address of the operator whose utilized SD needs to be transferred back.
*/
function _transferBackUtilizedSD(address operator) internal {
ISDCollateral sdCollateral = ISDCollateral(staderConfig.getSDCollateral());
(, , uint256 nonTerminalKeys) = sdCollateral.getOperatorInfo(operator);

uint256 operatorUtilizedSDBal = sdCollateral.operatorUtilizedSDBalance(operator);

// Only proceed if the operator has no non-terminal (active) keys left and nonZero utilizedSD Balance
if (nonTerminalKeys > 0 || (operatorUtilizedSDBal == 0)) return;

// transfer back the operator's utilized SD balance to SD Utility Pool
sdCollateral.transferBackUtilizedSD(operator);
}
}
Loading
Loading