Skip to main content

RegenEarningPowerCalculator

Git Source

Inherits: IAccessControlledEarningPowerCalculator, Ownable, ERC165

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

NameTypeDescription
_owneraddressAddress that will own this contract
_allowsetIAddressSetAllowset contract address (active in ALLOWSET mode)
_blocksetIAddressSetBlockset contract address (active in BLOCKSET mode)
_accessModeAccessModeInitial 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

NameTypeDescription
stakeraddressAddress to check

Returns

NameTypeDescription
hasAccessboolTrue 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)
external
view
override
returns (uint256 earningPower);

Parameters

NameTypeDescription
stakedAmountuint256Amount of staked tokens in token base units
stakeraddressAddress of staker
<none>address

Returns

NameTypeDescription
earningPoweruint256Calculated 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, uint256 oldEarningPower)
external
view
override
returns (uint256 newCalculatedEarningPower, bool qualifiesForBump);

Parameters

NameTypeDescription
stakedAmountuint256Amount of staked tokens in token base units
stakeraddressAddress of staker
<none>address
oldEarningPoweruint256Previous earning power value

Returns

NameTypeDescription
newCalculatedEarningPoweruint256New earning power (0 if no access)
qualifiesForBumpboolTrue 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

NameTypeDescription
_allowsetIAddressSetAllowset 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

NameTypeDescription
_blocksetIAddressSetBlockset 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

NameTypeDescription
_modeAccessModeAccess 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

NameTypeDescription
interfaceIdbytes4Interface identifier to check

Returns

NameTypeDescription
supportedboolTrue 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);