RegenEarningPowerCalculator
Inherits: IAccessControlledEarningPowerCalculator, Ownable, ERC165
Title: RegenEarningPowerCalculator
Author: Golem Foundation
Calculates staking earning power with access control
Linear earning power calculation with access control gates EARNING POWER FORMULA: earningPower = min(stakedAmount, type(uint96).max) ACCESS CONTROL MODES:
- NONE: Everyone has access (permissionless)
- ALLOWSET: Only addresses in allowset
- BLOCKSET: All except addresses in blockset BEHAVIOR:
- If user has access: earningPower = staked amount (capped at uint96 max)
- If user lacks access: earningPower = 0 (no rewards) BUMP QUALIFICATION: User qualifies for earning power bump when:
- Access status changes (added/removed from set)
- Staked amount changes
- Old earning power ≠ new earning power
Notes:
-
security-contact: [email protected]
-
security: Access control determines reward eligibility
State Variables
allowset
The allowset contract that determines which addresses are eligible to earn power (ALLOWSET mode)
Active only when accessMode == AccessMode.ALLOWSET
IAddressSet public override allowset
blockset
The blockset contract that determines which addresses are blocked from earning (BLOCKSET mode)
Active only when accessMode == AccessMode.BLOCKSET
IAddressSet public blockset
accessMode
Current access mode for earning power
Determines which address set is active
AccessMode public accessMode
Functions
constructor
Initializes the RegenEarningPowerCalculator with access control configuration
Sets all address sets and access mode during deployment NOTE: AccessMode determines which address set is active, not address(0) checks
constructor(address _owner, IAddressSet _allowset, IAddressSet _blockset, AccessMode _accessMode) Ownable(_owner);
Parameters
| Name | Type | Description |
|---|---|---|
_owner | address | Address that will own this contract |
_allowset | IAddressSet | Allowset contract address (active in ALLOWSET mode) |
_blockset | IAddressSet | Blockset contract address (active in BLOCKSET mode) |
_accessMode | AccessMode | Initial access mode (NONE, ALLOWSET, or BLOCKSET) |
_hasAccess
Check if staker has access based on current access mode
Internal helper to centralize access control logic ACCESS LOGIC:
- NONE: Always returns true
- ALLOWSET: Returns allowset.contains(staker)
- BLOCKSET: Returns !blockset.contains(staker)
function _hasAccess(address staker) internal view returns (bool hasAccess);
Parameters
| Name | Type | Description |
|---|---|---|
staker | address | Address to check |
Returns
| Name | Type | Description |
|---|---|---|
hasAccess | bool | True if staker has access to earn rewards |
getEarningPower
Returns the earning power of a staker
Earning power = staked amount (capped at uint96 max) if has access, else 0 FORMULA:
- Has access: min(stakedAmount, type(uint96).max)
- No access: 0
function getEarningPower(
uint256 stakedAmount,
address staker,
address /*_delegatee*/
)
external
view
override
returns (uint256 earningPower);
Parameters
| Name | Type | Description |
|---|---|---|
stakedAmount | uint256 | Amount of staked tokens in token base units |
staker | address | Address of staker |
<none> | address |
Returns
| Name | Type | Description |
|---|---|---|
earningPower | uint256 | Calculated earning power (0 if no access) |
getNewEarningPower
Returns the new earning power and bump qualification status
Calculates new earning power based on access control and staked amount A staker qualifies for a bump whenever their earning power changes BUMP QUALIFICATION CONDITIONS:
- Access status changed (added/removed from set)
- Staked amount changed
- Any change where: newEarningPower ≠ oldEarningPower This ensures deposits are updated promptly when access status changes.
function getNewEarningPower(
uint256 stakedAmount,
address staker,
address, // _delegatee - unused
uint256 oldEarningPower
)
external
view
override
returns (uint256 newCalculatedEarningPower, bool qualifiesForBump);
Parameters
| Name | Type | Description |
|---|---|---|
stakedAmount | uint256 | Amount of staked tokens in token base units |
staker | address | Address of staker |
<none> | address | |
oldEarningPower | uint256 | Previous earning power value |
Returns
| Name | Type | Description |
|---|---|---|
newCalculatedEarningPower | uint256 | New earning power (0 if no access) |
qualifiesForBump | bool | True if earning power changed |
setAllowset
Sets the allowset for the earning power calculator (ALLOWSET mode)
Only callable by owner. Use setAccessMode(AccessMode.NONE) to disable access control
Note: security: Only owner can modify access control
function setAllowset(IAddressSet _allowset) public override onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
_allowset | IAddressSet | Allowset contract address to set |
setBlockset
Sets the blockset for the earning power calculator (BLOCKSET mode)
Only callable by owner. Use setAccessMode(AccessMode.NONE) to disable access control
Note: security: Only owner can modify access control
function setBlockset(IAddressSet _blockset) public onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
_blockset | IAddressSet | Blockset contract address to set |
setAccessMode
Sets the access mode for the earning power calculator
Non-retroactive. Existing deposits require bumpEarningPower() to reflect changes Only callable by owner
Notes:
-
security: Only owner can change access mode
-
security: Non-retroactive - requires manual bumping to apply to existing deposits
function setAccessMode(AccessMode _mode) public onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
_mode | AccessMode | Access mode to set (NONE, ALLOWSET, or BLOCKSET) |
supportsInterface
Checks interface support including IAccessControlledEarningPowerCalculator
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC165, IERC165)
returns (bool supported);
Parameters
| Name | Type | Description |
|---|---|---|
interfaceId | bytes4 | Interface identifier to check |
Returns
| Name | Type | Description |
|---|---|---|
supported | bool | True if interface is supported |
Events
BlocksetAssigned
Emitted when blockset is updated
event BlocksetAssigned(IAddressSet indexed blockset);
AccessModeSet
Emitted when access mode is changed
event AccessModeSet(AccessMode indexed mode);