staking docs

Staking

constructor

constructor(address grgVault, address poolRegistry, address rigoToken) public

Setting owner to null address prevents admin direct calls to implementation.

Initializing immutable implementation address is used to allow delegatecalls only. Direct calls to the implementation contract are effectively locked.

Parameters

NameTypeDescription

grgVault

address

Address of the Grg vault.

poolRegistry

address

Address of the RigoBlock pool registry.

rigoToken

address

Address of the Grg token.

init

function init() public

Initialize storage owned by this contract.

This function should not be called directly. The StakingProxy contract will call it in attachStakingContract().

MixinConstants

_PPM_DENOMINATOR

uint32 _PPM_DENOMINATOR

_NIL_POOL_ID

bytes32 _NIL_POOL_ID

_NIL_ADDRESS

address _NIL_ADDRESS

_MIN_TOKEN_VALUE

uint256 _MIN_TOKEN_VALUE

MixinDeploymentConstants

constructor

constructor(address grgVault, address poolRegistry, address rigoToken) internal

_implementation

address _implementation

_rigoToken

address _rigoToken

_grgVault

address _grgVault

_poolRegistry

address _poolRegistry

getGrgContract

function getGrgContract() public view virtual returns (contract IRigoToken)

An overridable way to access the deployed GRG contract.

Must be view to allow overrides to access state.

Return Values

NameTypeDescription

[0]

contract IRigoToken

The GRG contract instance.

getGrgVault

function getGrgVault() public view virtual returns (contract IGrgVault)

An overridable way to access the deployed grgVault.

Must be view to allow overrides to access state.

Return Values

NameTypeDescription

[0]

contract IGrgVault

The GRG vault contract.

getPoolRegistry

function getPoolRegistry() public view virtual returns (contract IPoolRegistry)

An overridable way to access the deployed rigoblock pool registry.

Must be view to allow overrides to access state.

Return Values

NameTypeDescription

[0]

contract IPoolRegistry

The pool registry contract.

MixinStorage

stakingContract

address stakingContract

Address of staking contract.

Return Values

_globalStakeByStatus

mapping(uint8 => struct IStructs.StoredBalance) _globalStakeByStatus

_ownerStakeByStatus

mapping(uint8 => mapping(address => struct IStructs.StoredBalance)) _ownerStakeByStatus

_delegatedStakeToPoolByOwner

mapping(address => mapping(bytes32 => struct IStructs.StoredBalance)) _delegatedStakeToPoolByOwner

_delegatedStakeByPoolId

mapping(bytes32 => struct IStructs.StoredBalance) _delegatedStakeByPoolId

poolIdByRbPoolAccount

mapping(address => bytes32) poolIdByRbPoolAccount

Mapping from RigoBlock pool subaccount to pool Id of rigoblock pool

0 RigoBlock pool subaccount address.

Return Values

_poolById

mapping(bytes32 => struct IStructs.Pool) _poolById

rewardsByPoolId

mapping(bytes32 => uint256) rewardsByPoolId

mapping from pool ID to reward balance of members

0 Pool ID.

Return Values

currentEpoch

uint256 currentEpoch

The current epoch.

Return Values

currentEpochStartTimeInSeconds

uint256 currentEpochStartTimeInSeconds

The current epoch start time.

Return Values

_cumulativeRewardsByPool

mapping(bytes32 => mapping(uint256 => struct IStructs.Fraction)) _cumulativeRewardsByPool

_cumulativeRewardsByPoolLastStored

mapping(bytes32 => uint256) _cumulativeRewardsByPoolLastStored

validPops

mapping(address => bool) validPops

Registered RigoBlock Proof_of_Performance contracts, capable of paying protocol fees.

0 The address to check.

Return Values

epochDurationInSeconds

uint256 epochDurationInSeconds

Minimum seconds between epochs.

Return Values

rewardDelegatedStakeWeight

uint32 rewardDelegatedStakeWeight

Return Values

minimumPoolStake

uint256 minimumPoolStake

Minimum amount of stake required in a pool to collect rewards.

Return Values

cobbDouglasAlphaNumerator

uint32 cobbDouglasAlphaNumerator

Numerator for cobb douglas alpha factor.

Return Values

cobbDouglasAlphaDenominator

uint32 cobbDouglasAlphaDenominator

Denominator for cobb douglas alpha factor.

Return Values

poolStatsByEpoch

mapping(bytes32 => mapping(uint256 => struct IStructs.PoolStats)) poolStatsByEpoch

Stats for each pool that generated fees with sufficient stake to earn rewards.

See _minimumPoolStake in MixinParams.

Parameters

Return Values

aggregatedStatsByEpoch

mapping(uint256 => struct IStructs.AggregatedStats) aggregatedStatsByEpoch

Aggregated stats across all pools that generated fees with sufficient stake to earn rewards.

See _minimumPoolStake in MixinParams.

Parameters

Return Values

grgReservedForPoolRewards

uint256 grgReservedForPoolRewards

The GRG balance of this contract that is reserved for pool reward payouts.

Return Values

IGrgVault

StakingProxySet

event StakingProxySet(address stakingProxyAddress)

Emmitted whenever a StakingProxy is set in a vault.

Parameters

NameTypeDescription

stakingProxyAddress

address

Address of the staking proxy contract.

InCatastrophicFailureMode

event InCatastrophicFailureMode(address sender)

Emitted when the Staking contract is put into Catastrophic Failure Mode

Parameters

NameTypeDescription

sender

address

Address of sender (msg.sender)

Deposit

event Deposit(address staker, uint256 amount)

Emitted when Grg Tokens are deposited into the vault.

Parameters

NameTypeDescription

staker

address

Address of the Grg staker.

amount

uint256

of Grg Tokens deposited.

Withdraw

event Withdraw(address staker, uint256 amount)

Emitted when Grg Tokens are withdrawn from the vault.

Parameters

NameTypeDescription

staker

address

Address of the Grg staker.

amount

uint256

of Grg Tokens withdrawn.

GrgProxySet

event GrgProxySet(address grgProxyAddress)

Emitted whenever the Grg AssetProxy is set.

Parameters

NameTypeDescription

grgProxyAddress

address

Address of the Grg transfer proxy.

setStakingProxy

function setStakingProxy(address stakingProxyAddress) external

Sets the address of the StakingProxy contract.

Note that only the contract staker can call this function.

Parameters

NameTypeDescription

stakingProxyAddress

address

Address of Staking proxy contract.

enterCatastrophicFailure

function enterCatastrophicFailure() external

Vault enters into Catastrophic Failure Mode.

*** WARNING - ONCE IN CATOSTROPHIC FAILURE MODE, YOU CAN NEVER GO BACK! *** Note that only the contract staker can call this function.

setGrgProxy

function setGrgProxy(address grgProxyAddress) external

Sets the Grg proxy.

Note that only the contract staker can call this. Note that this can only be called when not in Catastrophic Failure mode.

Parameters

NameTypeDescription

grgProxyAddress

address

Address of the RigoBlock Grg Proxy.

depositFrom

function depositFrom(address staker, uint256 amount) external

Deposit an amount of Grg Tokens from staker into the vault.

Note that only the Staking contract can call this. Note that this can only be called when not in Catastrophic Failure mode.

Parameters

NameTypeDescription

staker

address

Address of the Grg staker.

amount

uint256

of Grg Tokens to deposit.

withdrawFrom

function withdrawFrom(address staker, uint256 amount) external

Withdraw an amount of Grg Tokens to staker from the vault.

Note that only the Staking contract can call this. Note that this can only be called when not in Catastrophic Failure mode.

Parameters

NameTypeDescription

staker

address

Address of the Grg staker.

amount

uint256

of Grg Tokens to withdraw.

withdrawAllFrom

function withdrawAllFrom(address staker) external returns (uint256)

Withdraw ALL Grg Tokens to staker from the vault.

Note that this can only be called when in Catastrophic Failure mode.

Parameters

NameTypeDescription

staker

address

Address of the Grg staker.

balanceOf

function balanceOf(address staker) external view returns (uint256)

Returns the balance in Grg Tokens of the staker

Parameters

NameTypeDescription

staker

address

Address of the Grg staker.

Return Values

NameTypeDescription

[0]

uint256

Balance in Grg.

balanceOfGrgVault

function balanceOfGrgVault() external view returns (uint256)

Returns the entire balance of Grg tokens in the vault.

Return Values

NameTypeDescription

[0]

uint256

Balance in Grg.

IStaking

addPopAddress

function addPopAddress(address addr) external

Adds a new proof_of_performance address.

Parameters

NameTypeDescription

addr

address

Address of proof_of_performance contract to add.

createStakingPool

function createStakingPool(address rigoblockPoolAddress) external returns (bytes32 poolId)

Create a new staking pool. The sender will be the staking pal of this pool.

Note that a staking pal must be payable. When governance updates registry address, pools must be migrated to new registry, or this contract must query from both.

Parameters

NameTypeDescription

rigoblockPoolAddress

address

Adds rigoblock pool to the created staking pool for convenience if non-null.

Return Values

NameTypeDescription

poolId

bytes32

The unique pool id generated for this pool.

setStakingPalAddress

function setStakingPalAddress(bytes32 poolId, address newStakingPalAddress) external

Allows the operator to update the staking pal address.

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

newStakingPalAddress

address

Address of the new staking pal.

decreaseStakingPoolOperatorShare

function decreaseStakingPoolOperatorShare(bytes32 poolId, uint32 newOperatorShare) external

Decreases the operator share for the given pool (i.e. increases pool rewards for members).

Parameters

NameTypeDescription

poolId

bytes32

Unique Id of pool.

newOperatorShare

uint32

The newly decreased percentage of any rewards owned by the operator.

endEpoch

function endEpoch() external returns (uint256 numPoolsToFinalize)

Begins a new epoch, preparing the prior one for finalization.

Throws if not enough time has passed between epochs or if the previous epoch was not fully finalized.

Return Values

NameTypeDescription

numPoolsToFinalize

uint256

The number of unfinalized pools.

finalizePool

function finalizePool(bytes32 poolId) external

Instantly finalizes a single pool that earned rewards in the previous epoch,

crediting it rewards for members and withdrawing operator's rewards as GRG. This can be called by internal functions that need to finalize a pool immediately. Does nothing if the pool is already finalized or did not earn rewards in the previous epoch.

Parameters

NameTypeDescription

poolId

bytes32

The pool ID to finalize.

init

function init() external

Initialize storage owned by this contract.

This function should not be called directly. The StakingProxy contract will call it in attachStakingContract().

moveStake

function moveStake(struct IStructs.StakeInfo from, struct IStructs.StakeInfo to, uint256 amount) external

Moves stake between statuses: 'undelegated' or 'delegated'.

Delegated stake can also be moved between pools. This change comes into effect next epoch.

Parameters

NameTypeDescription

from

struct IStructs.StakeInfo

Status to move stake out of.

to

struct IStructs.StakeInfo

Status to move stake into.

amount

uint256

Amount of stake to move.

creditPopReward

function creditPopReward(address poolAccount, uint256 popReward) external payable

Credits the value of a pool's pop reward.

Only a known RigoBlock pop can call this method. See (MixinPopManager).

Parameters

NameTypeDescription

poolAccount

address

The address of the rigoblock pool account.

popReward

uint256

The pop reward.

removePopAddress

function removePopAddress(address addr) external

Removes an existing proof_of_performance address.

Parameters

NameTypeDescription

addr

address

Address of proof_of_performance contract to remove.

setParams

function setParams(uint256 _epochDurationInSeconds, uint32 _rewardDelegatedStakeWeight, uint256 _minimumPoolStake, uint32 _cobbDouglasAlphaNumerator, uint32 _cobbDouglasAlphaDenominator) external

Set all configurable parameters at once.

Parameters

NameTypeDescription

_epochDurationInSeconds

uint256

Minimum seconds between epochs.

_rewardDelegatedStakeWeight

uint32

How much delegated stake is weighted vs operator stake, in ppm.

_minimumPoolStake

uint256

Minimum amount of stake required in a pool to collect rewards.

_cobbDouglasAlphaNumerator

uint32

Numerator for cobb douglas alpha factor.

_cobbDouglasAlphaDenominator

uint32

Denominator for cobb douglas alpha factor.

stake

function stake(uint256 amount) external

Stake GRG tokens. Tokens are deposited into the GRG Vault.

Unstake to retrieve the GRG. Stake is in the 'Active' status.

Parameters

NameTypeDescription

amount

uint256

of GRG to stake.

unstake

function unstake(uint256 amount) external

Unstake. Tokens are withdrawn from the GRG Vault and returned to the staker.

Stake must be in the 'undelegated' status in both the current and next epoch in order to be unstaked.

Parameters

NameTypeDescription

amount

uint256

of GRG to unstake.

withdrawDelegatorRewards

function withdrawDelegatorRewards(bytes32 poolId) external

Withdraws the caller's GRG rewards that have accumulated until the last epoch.

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

computeRewardBalanceOfDelegator

function computeRewardBalanceOfDelegator(bytes32 poolId, address member) external view returns (uint256 reward)

Computes the reward balance in GRG of a specific member of a pool.

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

member

address

The member of the pool.

Return Values

NameTypeDescription

reward

uint256

Balance in GRG.

computeRewardBalanceOfOperator

function computeRewardBalanceOfOperator(bytes32 poolId) external view returns (uint256 reward)

Computes the reward balance in GRG of the operator of a pool.

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

Return Values

NameTypeDescription

reward

uint256

Balance in GRG.

getCurrentEpochEarliestEndTimeInSeconds

function getCurrentEpochEarliestEndTimeInSeconds() external view returns (uint256)

Returns the earliest end time in seconds of this epoch.

The next epoch can begin once this time is reached. Epoch period = [startTimeInSeconds..endTimeInSeconds)

Return Values

NameTypeDescription

[0]

uint256

Time in seconds.

getGlobalStakeByStatus

function getGlobalStakeByStatus(enum IStructs.StakeStatus stakeStatus) external view returns (struct IStructs.StoredBalance balance)

Gets global stake for a given status.

Parameters

NameTypeDescription

stakeStatus

enum IStructs.StakeStatus

UNDELEGATED or DELEGATED

Return Values

NameTypeDescription

balance

struct IStructs.StoredBalance

Global stake for given status.

getOwnerStakeByStatus

function getOwnerStakeByStatus(address staker, enum IStructs.StakeStatus stakeStatus) external view returns (struct IStructs.StoredBalance balance)

Gets an owner's stake balances by status.

Parameters

NameTypeDescription

staker

address

Owner of stake.

stakeStatus

enum IStructs.StakeStatus

UNDELEGATED or DELEGATED

Return Values

NameTypeDescription

balance

struct IStructs.StoredBalance

Owner's stake balances for given status.

getTotalStake

function getTotalStake(address staker) external view returns (uint256)

Returns the total stake for a given staker.

Parameters

NameTypeDescription

staker

address

of stake.

Return Values

NameTypeDescription

[0]

uint256

Total GRG staked by staker.

getParams

function getParams() external view returns (uint256 _epochDurationInSeconds, uint32 _rewardDelegatedStakeWeight, uint256 _minimumPoolStake, uint32 _cobbDouglasAlphaNumerator, uint32 _cobbDouglasAlphaDenominator)

Retrieves all configurable parameter values.

Return Values

NameTypeDescription

_epochDurationInSeconds

uint256

Minimum seconds between epochs.

_rewardDelegatedStakeWeight

uint32

How much delegated stake is weighted vs operator stake, in ppm.

_minimumPoolStake

uint256

Minimum amount of stake required in a pool to collect rewards.

_cobbDouglasAlphaNumerator

uint32

Numerator for cobb douglas alpha factor.

_cobbDouglasAlphaDenominator

uint32

Denominator for cobb douglas alpha factor.

getStakeDelegatedToPoolByOwner

function getStakeDelegatedToPoolByOwner(address staker, bytes32 poolId) external view returns (struct IStructs.StoredBalance balance)

Returns stake delegated to pool by staker.

Parameters

NameTypeDescription

staker

address

of stake.

poolId

bytes32

Unique Id of pool.

Return Values

NameTypeDescription

balance

struct IStructs.StoredBalance

Stake delegated to pool by staker.

getStakingPool

function getStakingPool(bytes32 poolId) external view returns (struct IStructs.Pool)

Returns a staking pool

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

getStakingPoolStatsThisEpoch

function getStakingPoolStatsThisEpoch(bytes32 poolId) external view returns (struct IStructs.PoolStats)

Get stats on a staking pool in this epoch.

Parameters

NameTypeDescription

poolId

bytes32

Pool Id to query.

Return Values

NameTypeDescription

[0]

struct IStructs.PoolStats

PoolStats struct for pool id.

getTotalStakeDelegatedToPool

function getTotalStakeDelegatedToPool(bytes32 poolId) external view returns (struct IStructs.StoredBalance balance)

Returns the total stake delegated to a specific staking pool, across all members.

Parameters

NameTypeDescription

poolId

bytes32

Unique Id of pool.

Return Values

NameTypeDescription

balance

struct IStructs.StoredBalance

Total stake delegated to pool.

getGrgContract

function getGrgContract() external view returns (contract IRigoToken)

An overridable way to access the deployed GRG contract.

Must be view to allow overrides to access state.

Return Values

NameTypeDescription

[0]

contract IRigoToken

The GRG contract instance.

getGrgVault

function getGrgVault() external view returns (contract IGrgVault)

An overridable way to access the deployed grgVault.

Must be view to allow overrides to access state.

Return Values

NameTypeDescription

[0]

contract IGrgVault

The GRG vault contract.

getPoolRegistry

function getPoolRegistry() external view returns (contract IPoolRegistry)

An overridable way to access the deployed rigoblock pool registry.

Must be view to allow overrides to access state.

Return Values

NameTypeDescription

[0]

contract IPoolRegistry

The pool registry contract.

IStakingEvents

Stake

event Stake(address staker, uint256 amount)

Emitted by MixinStake when GRG is staked.

Parameters

NameTypeDescription

staker

address

of GRG.

amount

uint256

of GRG staked.

Unstake

event Unstake(address staker, uint256 amount)

Emitted by MixinStake when GRG is unstaked.

Parameters

NameTypeDescription

staker

address

of GRG.

amount

uint256

of GRG unstaked.

MoveStake

event MoveStake(address staker, uint256 amount, uint8 fromStatus, bytes32 fromPool, uint8 toStatus, bytes32 toPool)

Emitted by MixinStake when GRG is unstaked.

Parameters

NameTypeDescription

staker

address

of GRG.

amount

uint256

of GRG unstaked.

fromStatus

uint8

fromPool

bytes32

toStatus

uint8

toPool

bytes32

PopAdded

event PopAdded(address exchangeAddress)

Emitted by MixinExchangeManager when an exchange is added.

Parameters

NameTypeDescription

exchangeAddress

address

Address of new exchange.

PopRemoved

event PopRemoved(address exchangeAddress)

Emitted by MixinExchangeManager when an exchange is removed.

Parameters

NameTypeDescription

exchangeAddress

address

Address of removed exchange.

StakingPoolEarnedRewardsInEpoch

event StakingPoolEarnedRewardsInEpoch(uint256 epoch, bytes32 poolId)

Emitted by MixinExchangeFees when a pool starts earning rewards in an epoch.

Parameters

NameTypeDescription

epoch

uint256

The epoch in which the pool earned rewards.

poolId

bytes32

The ID of the pool.

EpochEnded

event EpochEnded(uint256 epoch, uint256 numPoolsToFinalize, uint256 rewardsAvailable, uint256 totalFeesCollected, uint256 totalWeightedStake)

Emitted by MixinFinalizer when an epoch has ended.

Parameters

NameTypeDescription

epoch

uint256

The epoch that ended.

numPoolsToFinalize

uint256

Number of pools that earned rewards during epoch and must be finalized.

rewardsAvailable

uint256

Rewards available to all pools that earned rewards during epoch.

totalFeesCollected

uint256

Total fees collected across all pools that earned rewards during epoch.

totalWeightedStake

uint256

Total weighted stake across all pools that earned rewards during epoch.

EpochFinalized

event EpochFinalized(uint256 epoch, uint256 rewardsPaid, uint256 rewardsRemaining)

Emitted by MixinFinalizer when an epoch is fully finalized.

Parameters

NameTypeDescription

epoch

uint256

The epoch being finalized.

rewardsPaid

uint256

Total amount of rewards paid out.

rewardsRemaining

uint256

Rewards left over.

RewardsPaid

event RewardsPaid(uint256 epoch, bytes32 poolId, uint256 operatorReward, uint256 membersReward)

Emitted by MixinFinalizer when rewards are paid out to a pool.

Parameters

NameTypeDescription

epoch

uint256

The epoch when the rewards were paid out.

poolId

bytes32

The pool's ID.

operatorReward

uint256

Amount of reward paid to pool operator.

membersReward

uint256

Amount of reward paid to pool members.

ParamsSet

event ParamsSet(uint256 epochDurationInSeconds, uint32 rewardDelegatedStakeWeight, uint256 minimumPoolStake, uint256 cobbDouglasAlphaNumerator, uint256 cobbDouglasAlphaDenominator)

Emitted whenever staking parameters are changed via the setParams() function.

Parameters

NameTypeDescription

epochDurationInSeconds

uint256

Minimum seconds between epochs.

rewardDelegatedStakeWeight

uint32

How much delegated stake is weighted vs operator stake, in ppm.

minimumPoolStake

uint256

Minimum amount of stake required in a pool to collect rewards.

cobbDouglasAlphaNumerator

uint256

Numerator for cobb douglas alpha factor.

cobbDouglasAlphaDenominator

uint256

Denominator for cobb douglas alpha factor.

StakingPoolCreated

event StakingPoolCreated(bytes32 poolId, address operator, uint32 operatorShare)

Emitted by MixinStakingPool when a new pool is created.

Parameters

NameTypeDescription

poolId

bytes32

Unique id generated for pool.

operator

address

The operator (creator) of pool.

operatorShare

uint32

The share of rewards given to the operator, in ppm.

RbPoolStakingPoolSet

event RbPoolStakingPoolSet(address rbPoolAddress, bytes32 poolId)

Emitted by MixinStakingPool when a rigoblock pool is added to its staking pool.

Parameters

NameTypeDescription

rbPoolAddress

address

Adress of maker added to pool.

poolId

bytes32

Unique id of pool.

OperatorShareDecreased

event OperatorShareDecreased(bytes32 poolId, uint32 oldOperatorShare, uint32 newOperatorShare)

Emitted when a staking pool's operator share is decreased.

Parameters

NameTypeDescription

poolId

bytes32

Unique Id of pool.

oldOperatorShare

uint32

Previous share of rewards owned by operator.

newOperatorShare

uint32

Newly decreased share of rewards owned by operator.

GrgMintEvent

event GrgMintEvent(uint256 grgAmount)

Emitted when an inflation mint call is executed successfully.

Parameters

NameTypeDescription

grgAmount

uint256

Amount of GRG tokens minted to the staking proxy.

CatchStringEvent

event CatchStringEvent(string reason)

Emitted whenever an inflation mint call is reverted.

Parameters

NameTypeDescription

reason

string

String of the revert message.

ReturnDataEvent

event ReturnDataEvent(bytes reason)

Emitted to catch any other inflation mint call fail.

Parameters

NameTypeDescription

reason

bytes

Bytes output of the reverted transaction.

IStakingProxy

StakingContractAttachedToProxy

event StakingContractAttachedToProxy(address newStakingContractAddress)

Emitted by StakingProxy when a staking contract is attached.

Parameters

NameTypeDescription

newStakingContractAddress

address

Address of newly attached staking contract.

StakingContractDetachedFromProxy

event StakingContractDetachedFromProxy()

Emitted by StakingProxy when a staking contract is detached.

attachStakingContract

function attachStakingContract(address stakingImplementation) external

Attach a staking contract; future calls will be delegated to the staking contract.

Note that this is callable only by an authorized address.

Parameters

NameTypeDescription

stakingImplementation

address

Address of staking contract.

detachStakingContract

function detachStakingContract() external

Detach the current staking contract.

Note that this is callable only by an authorized address.

batchExecute

function batchExecute(bytes[] data) external returns (bytes[] batchReturnData)

Batch executes a series of calls to the staking contract.

Parameters

NameTypeDescription

data

bytes[]

An array of data that encodes a sequence of functions to call in the staking contracts.

assertValidStorageParams

function assertValidStorageParams() external view

Asserts initialziation parameters are correct.

Asserts that an epoch is between 5 and 30 days long. Asserts that 0 < cobb douglas alpha value <= 1. Asserts that a stake weight is <= 100%. Asserts that pools allow >= 1 maker. Asserts that all addresses are initialized.

IStorage

stakingContract

function stakingContract() external view returns (address)

Address of staking contract.

Return Values

NameTypeDescription

[0]

address

stakingContract Address of the staking contract.

poolIdByRbPoolAccount

function poolIdByRbPoolAccount(address) external view returns (bytes32)

Mapping from RigoBlock pool subaccount to pool Id of rigoblock pool

0 RigoBlock pool subaccount address.

Return Values

NameTypeDescription

[0]

bytes32

0 The pool ID.

rewardsByPoolId

function rewardsByPoolId(bytes32) external view returns (uint256)

mapping from pool ID to reward balance of members

0 Pool ID.

Return Values

NameTypeDescription

[0]

uint256

0 The total reward balance of members in this pool.

currentEpoch

function currentEpoch() external view returns (uint256)

The current epoch.

Return Values

NameTypeDescription

[0]

uint256

currentEpoch The number of the current epoch.

currentEpochStartTimeInSeconds

function currentEpochStartTimeInSeconds() external view returns (uint256)

The current epoch start time.

Return Values

NameTypeDescription

[0]

uint256

currentEpochStartTimeInSeconds Timestamp of start time.

validPops

function validPops(address popAddress) external view returns (bool)

Registered RigoBlock Proof_of_Performance contracts, capable of paying protocol fees.

0 The address to check.

Return Values

NameTypeDescription

[0]

bool

0 Whether the address is a registered proof_of_performance.

epochDurationInSeconds

function epochDurationInSeconds() external view returns (uint256)

Minimum seconds between epochs.

Return Values

NameTypeDescription

[0]

uint256

epochDurationInSeconds Number of seconds.

rewardDelegatedStakeWeight

function rewardDelegatedStakeWeight() external view returns (uint32)

Return Values

NameTypeDescription

[0]

uint32

rewardDelegatedStakeWeight Number in units of a million.

minimumPoolStake

function minimumPoolStake() external view returns (uint256)

Minimum amount of stake required in a pool to collect rewards.

Return Values

NameTypeDescription

[0]

uint256

minimumPoolStake Minimum amount required.

cobbDouglasAlphaNumerator

function cobbDouglasAlphaNumerator() external view returns (uint32)

Numerator for cobb douglas alpha factor.

Return Values

NameTypeDescription

[0]

uint32

cobbDouglasAlphaNumerator Number of the numerator.

cobbDouglasAlphaDenominator

function cobbDouglasAlphaDenominator() external view returns (uint32)

Denominator for cobb douglas alpha factor.

Return Values

NameTypeDescription

[0]

uint32

cobbDouglasAlphaDenominator Number of the denominator.

poolStatsByEpoch

function poolStatsByEpoch(bytes32 key, uint256 epoch) external view returns (uint256 feesCollected, uint256 weightedStake, uint256 membersStake)

Stats for each pool that generated fees with sufficient stake to earn rewards.

See _minimumPoolStake in MixinParams.

Parameters

NameTypeDescription

key

bytes32

Pool ID.

epoch

uint256

Epoch number.

Return Values

NameTypeDescription

feesCollected

uint256

Amount of fees collected in epoch.

weightedStake

uint256

Weighted stake per million.

membersStake

uint256

Members stake per million.

aggregatedStatsByEpoch

function aggregatedStatsByEpoch(uint256 epoch) external view returns (uint256 rewardsAvailable, uint256 numPoolsToFinalize, uint256 totalFeesCollected, uint256 totalWeightedStake, uint256 totalRewardsFinalized)

Aggregated stats across all pools that generated fees with sufficient stake to earn rewards.

See _minimumPoolStake in MixinParams.

Parameters

NameTypeDescription

epoch

uint256

Epoch number.

Return Values

NameTypeDescription

rewardsAvailable

uint256

Rewards (GRG) available to the epoch being finalized (the previous epoch).

numPoolsToFinalize

uint256

The number of pools that have yet to be finalized through finalizePools().

totalFeesCollected

uint256

The total fees collected for the epoch being finalized.

totalWeightedStake

uint256

The total fees collected for the epoch being finalized.

totalRewardsFinalized

uint256

Amount of rewards that have been paid during finalization.

grgReservedForPoolRewards

function grgReservedForPoolRewards() external view returns (uint256)

The GRG balance of this contract that is reserved for pool reward payouts.

Return Values

NameTypeDescription

[0]

uint256

grgReservedForPoolRewards Number of tokens reserved for rewards.

IStorageInit

init

function init() external

Initialize storage owned by this contract.

IStructs

PoolStats

struct PoolStats {
  uint256 feesCollected;
  uint256 weightedStake;
  uint256 membersStake;
}

AggregatedStats

struct AggregatedStats {
  uint256 rewardsAvailable;
  uint256 numPoolsToFinalize;
  uint256 totalFeesCollected;
  uint256 totalWeightedStake;
  uint256 totalRewardsFinalized;
}

StoredBalance

struct StoredBalance {
  uint64 currentEpoch;
  uint96 currentEpochBalance;
  uint96 nextEpochBalance;
}

StakeStatus

enum StakeStatus {
  UNDELEGATED,
  DELEGATED
}

StakeInfo

struct StakeInfo {
  enum IStructs.StakeStatus status;
  bytes32 poolId;
}

Fraction

struct Fraction {
  uint256 numerator;
  uint256 denominator;
}

Pool

struct Pool {
  address operator;
  address stakingPal;
  uint32 operatorShare;
  uint32 stakingPalShare;
}

LibCobbDouglas

cobbDouglas

function cobbDouglas(uint256 totalRewards, uint256 fees, uint256 totalFees, uint256 stake, uint256 totalStake, uint32 alphaNumerator, uint32 alphaDenominator) internal pure returns (uint256 rewards)

The cobb-douglas function used to compute fee-based rewards for staking pools in a given epoch. This function does not perform bounds checking on the inputs, but the following conditions need to be true: 0 <= fees / totalFees <= 1 0 <= stake / totalStake <= 1 0 <= alphaNumerator / alphaDenominator <= 1

Parameters

NameTypeDescription

totalRewards

uint256

collected over an epoch.

fees

uint256

Fees attributed to the the staking pool.

totalFees

uint256

Total fees collected across all pools that earned rewards.

stake

uint256

Stake attributed to the staking pool.

totalStake

uint256

Total stake across all pools that earned rewards.

alphaNumerator

uint32

Numerator of alpha in the cobb-douglas function.

alphaDenominator

uint32

Denominator of alpha in the cobb-douglas function.

Return Values

NameTypeDescription

rewards

uint256

Rewards owed to the staking pool.

LibFixedMath

Signed, fixed-point, 127-bit precision math library.

FIXED_1

int256 FIXED_1

MIN_FIXED_VAL

int256 MIN_FIXED_VAL

FIXED_1_SQUARED

int256 FIXED_1_SQUARED

LN_MAX_VAL

int256 LN_MAX_VAL

LN_MIN_VAL

int256 LN_MIN_VAL

EXP_MAX_VAL

int256 EXP_MAX_VAL

EXP_MIN_VAL

int256 EXP_MIN_VAL

mul

function mul(int256 a, int256 b) internal pure returns (int256 c)

Returns the multiplication of two fixed point numbers, reverting on overflow.

div

function div(int256 a, int256 b) internal pure returns (int256 c)

Returns the division of two fixed point numbers.

mulDiv

function mulDiv(int256 a, int256 n, int256 d) internal pure returns (int256 c)

Performs (a * n) / d, without scaling for precision.

uintMul

function uintMul(int256 f, uint256 u) internal pure returns (uint256)

Returns the unsigned integer result of multiplying a fixed-point number with an integer, reverting if the multiplication overflows. Negative results are clamped to zero.

toFixed

function toFixed(uint256 n, uint256 d) internal pure returns (int256 f)

Convert unsigned n / d to a fixed-point number. Reverts if n / d is too large to fit in a fixed-point number.

ln

function ln(int256 x) internal pure returns (int256 r)

Get the natural logarithm of a fixed-point number 0 < x <= LN_MAX_VAL

exp

function exp(int256 x) internal pure returns (int256 r)

Compute the natural exponent for a fixed-point number EXP_MIN_VAL <= x <= 1

_mul

function _mul(int256 a, int256 b) private pure returns (int256 c)

Returns the multiplication two numbers, reverting on overflow.

_div

function _div(int256 a, int256 b) private pure returns (int256 c)

Returns the division of two numbers, reverting on division by zero.

LibSafeDowncast

downcastToUint96

function downcastToUint96(uint256 a) internal pure returns (uint96 b)

Safely downcasts to a uint96 Note that this reverts if the input value is too large.

downcastToUint64

function downcastToUint64(uint256 a) internal pure returns (uint64 b)

Safely downcasts to a uint64 Note that this reverts if the input value is too large.

MixinPopManager

addPopAddress

function addPopAddress(address addr) external

Adds a new proof_of_performance address.

Parameters

NameTypeDescription

addr

address

Address of proof_of_performance contract to add.

removePopAddress

function removePopAddress(address addr) external

Removes an existing proof_of_performance address.

Parameters

NameTypeDescription

addr

address

Address of proof_of_performance contract to remove.

MixinPopRewards

onlyPop

modifier onlyPop()

Asserts that the call is coming from a valid pop.

creditPopReward

function creditPopReward(address poolAccount, uint256 popReward) external payable

Credits the value of a pool's pop reward.

Only a known RigoBlock pop can call this method. See (MixinPopManager).

Parameters

NameTypeDescription

poolAccount

address

The address of the rigoblock pool account.

popReward

uint256

The pop reward.

getStakingPoolStatsThisEpoch

function getStakingPoolStatsThisEpoch(bytes32 poolId) external view returns (struct IStructs.PoolStats)

Get stats on a staking pool in this epoch.

Parameters

NameTypeDescription

poolId

bytes32

Pool Id to query.

Return Values

NameTypeDescription

[0]

struct IStructs.PoolStats

PoolStats struct for pool id.

_computeMembersAndWeightedStake

function _computeMembersAndWeightedStake(bytes32 poolId, uint256 totalStake) private view returns (uint256 membersStake, uint256 weightedStake)

Computes the members and weighted stake for a pool at the current epoch.

Parameters

NameTypeDescription

poolId

bytes32

ID of the pool.

totalStake

uint256

Total (unweighted) stake in the pool.

Return Values

NameTypeDescription

membersStake

uint256

Non-operator stake in the pool.

weightedStake

uint256

Weighted stake of the pool.

MixinStake

stake

function stake(uint256 amount) external

Stake GRG tokens. Tokens are deposited into the GRG Vault.

Unstake to retrieve the GRG. Stake is in the 'Active' status.

Parameters

NameTypeDescription

amount

uint256

of GRG to stake.

unstake

function unstake(uint256 amount) external

Unstake. Tokens are withdrawn from the GRG Vault and returned to the staker.

Stake must be in the 'undelegated' status in both the current and next epoch in order to be unstaked.

Parameters

NameTypeDescription

amount

uint256

of GRG to unstake.

moveStake

function moveStake(struct IStructs.StakeInfo from, struct IStructs.StakeInfo to, uint256 amount) external

Moves stake between statuses: 'undelegated' or 'delegated'.

Delegated stake can also be moved between pools. This change comes into effect next epoch.

Parameters

NameTypeDescription

from

struct IStructs.StakeInfo

Status to move stake out of.

to

struct IStructs.StakeInfo

Status to move stake into.

amount

uint256

Amount of stake to move.

_delegateStake

function _delegateStake(bytes32 poolId, address staker, uint256 amount) private

Delegates a owners stake to a staking pool.

Parameters

NameTypeDescription

poolId

bytes32

Id of pool to delegate to.

staker

address

Owner who wants to delegate.

amount

uint256

Amount of stake to delegate.

_undelegateStake

function _undelegateStake(bytes32 poolId, address staker, uint256 amount) private

Un-Delegates a owners stake from a staking pool.

Parameters

NameTypeDescription

poolId

bytes32

Id of pool to un-delegate from.

staker

address

Owner who wants to un-delegate.

amount

uint256

Amount of stake to un-delegate.

MixinStakeBalances

getGlobalStakeByStatus

function getGlobalStakeByStatus(enum IStructs.StakeStatus stakeStatus) external view returns (struct IStructs.StoredBalance balance)

Gets global stake for a given status.

Parameters

NameTypeDescription

stakeStatus

enum IStructs.StakeStatus

UNDELEGATED or DELEGATED

Return Values

NameTypeDescription

balance

struct IStructs.StoredBalance

Global stake for given status.

getOwnerStakeByStatus

function getOwnerStakeByStatus(address staker, enum IStructs.StakeStatus stakeStatus) external view returns (struct IStructs.StoredBalance balance)

Gets an owner's stake balances by status.

Parameters

NameTypeDescription

staker

address

Owner of stake.

stakeStatus

enum IStructs.StakeStatus

UNDELEGATED or DELEGATED

Return Values

NameTypeDescription

balance

struct IStructs.StoredBalance

Owner's stake balances for given status.

getTotalStake

function getTotalStake(address staker) public view returns (uint256)

Returns the total stake for a given staker.

Parameters

NameTypeDescription

staker

address

of stake.

Return Values

NameTypeDescription

[0]

uint256

Total GRG staked by staker.

getStakeDelegatedToPoolByOwner

function getStakeDelegatedToPoolByOwner(address staker, bytes32 poolId) public view returns (struct IStructs.StoredBalance balance)

Returns stake delegated to pool by staker.

Parameters

NameTypeDescription

staker

address

of stake.

poolId

bytes32

Unique Id of pool.

Return Values

NameTypeDescription

balance

struct IStructs.StoredBalance

Stake delegated to pool by staker.

getTotalStakeDelegatedToPool

function getTotalStakeDelegatedToPool(bytes32 poolId) public view returns (struct IStructs.StoredBalance balance)

Returns the total stake delegated to a specific staking pool, across all members.

Parameters

NameTypeDescription

poolId

bytes32

Unique Id of pool.

Return Values

NameTypeDescription

balance

struct IStructs.StoredBalance

Total stake delegated to pool.

MixinStakeStorage

This mixin contains logic for managing stake storage.

_moveStake

function _moveStake(struct IStructs.StoredBalance fromPtr, struct IStructs.StoredBalance toPtr, uint256 amount) internal

Moves stake between states: 'undelegated' or 'delegated'. This change comes into effect next epoch.

Parameters

NameTypeDescription

fromPtr

struct IStructs.StoredBalance

pointer to storage location of from stake.

toPtr

struct IStructs.StoredBalance

pointer to storage location of to stake.

amount

uint256

of stake to move.

_loadCurrentBalance

function _loadCurrentBalance(struct IStructs.StoredBalance balancePtr) internal view returns (struct IStructs.StoredBalance balance)

Loads a balance from storage and updates its fields to reflect values for the current epoch.

Parameters

NameTypeDescription

balancePtr

struct IStructs.StoredBalance

to load.

Return Values

NameTypeDescription

balance

struct IStructs.StoredBalance

current balance.

_increaseCurrentAndNextBalance

function _increaseCurrentAndNextBalance(struct IStructs.StoredBalance balancePtr, uint256 amount) internal

Increments both the current and next fields.

Parameters

NameTypeDescription

balancePtr

struct IStructs.StoredBalance

storage pointer to balance.

amount

uint256

to mint.

_decreaseCurrentAndNextBalance

function _decreaseCurrentAndNextBalance(struct IStructs.StoredBalance balancePtr, uint256 amount) internal

Decrements both the current and next fields.

Parameters

NameTypeDescription

balancePtr

struct IStructs.StoredBalance

storage pointer to balance.

amount

uint256

to mint.

_increaseNextBalance

function _increaseNextBalance(struct IStructs.StoredBalance balancePtr, uint256 amount) internal

Increments the next field (but not the current field).

Parameters

NameTypeDescription

balancePtr

struct IStructs.StoredBalance

storage pointer to balance.

amount

uint256

to increment by.

_decreaseNextBalance

function _decreaseNextBalance(struct IStructs.StoredBalance balancePtr, uint256 amount) internal

Decrements the next field (but not the current field).

Parameters

NameTypeDescription

balancePtr

struct IStructs.StoredBalance

storage pointer to balance.

amount

uint256

to decrement by.

_storeBalance

function _storeBalance(struct IStructs.StoredBalance balancePtr, struct IStructs.StoredBalance balance) private

Stores a balance in storage.

Parameters

NameTypeDescription

balancePtr

struct IStructs.StoredBalance

points to where balance will be stored.

balance

struct IStructs.StoredBalance

to save to storage.

_arePointersEqual

function _arePointersEqual(struct IStructs.StoredBalance balancePtrA, struct IStructs.StoredBalance balancePtrB) private pure returns (bool areEqual)

Returns true iff storage pointers resolve to same storage location.

Parameters

NameTypeDescription

balancePtrA

struct IStructs.StoredBalance

first storage pointer.

balancePtrB

struct IStructs.StoredBalance

second storage pointer.

Return Values

NameTypeDescription

areEqual

bool

true iff pointers are equal.

MixinCumulativeRewards

_isCumulativeRewardSet

function _isCumulativeRewardSet(struct IStructs.Fraction cumulativeReward) internal pure returns (bool)

returns true iff Cumulative Rewards are set

_addCumulativeReward

function _addCumulativeReward(bytes32 poolId, uint256 reward, uint256 stake) internal

Sets a pool's cumulative delegator rewards for the current epoch, given the rewards earned and stake from the last epoch, which will be summed with the previous cumulative rewards for this pool. If the last cumulative reward epoch is the current epoch, this is a no-op.

Parameters

NameTypeDescription

poolId

bytes32

The pool ID.

reward

uint256

The total reward earned by pool delegators from the last epoch.

stake

uint256

The total delegated stake in the pool in the last epoch.

_updateCumulativeReward

function _updateCumulativeReward(bytes32 poolId) internal

Sets a pool's cumulative delegator rewards for the current epoch, using the last stored cumulative rewards. If we've already set a CR for this epoch, this is a no-op.

Parameters

NameTypeDescription

poolId

bytes32

The pool ID.

_computeMemberRewardOverInterval

function _computeMemberRewardOverInterval(bytes32 poolId, uint256 memberStakeOverInterval, uint256 beginEpoch, uint256 endEpoch) internal view returns (uint256 reward)

Computes a member's reward over a given epoch interval.

Parameters

NameTypeDescription

poolId

bytes32

Uniqud Id of pool.

memberStakeOverInterval

uint256

Stake delegated to pool by member over the interval.

beginEpoch

uint256

Beginning of interval.

endEpoch

uint256

End of interval.

Return Values

NameTypeDescription

reward

uint256

Reward accumulated over interval [beginEpoch, endEpoch]

_getCumulativeRewardAtEpoch

function _getCumulativeRewardAtEpoch(bytes32 poolId, uint256 epoch) private view returns (struct IStructs.Fraction cumulativeReward)

Fetch the cumulative reward for a given epoch. If the corresponding CR does not exist in state, then we backtrack to find its value by querying epoch-1 and then most recent CR.

Parameters

NameTypeDescription

poolId

bytes32

Unique ID of pool.

epoch

uint256

The epoch to find the

Return Values

NameTypeDescription

cumulativeReward

struct IStructs.Fraction

The cumulative reward for poolId at epoch.

MixinStakingPool

onlyStakingPoolOperator

modifier onlyStakingPoolOperator(bytes32 poolId)

Asserts that the sender is the operator of the input pool.

Parameters

NameTypeDescription

poolId

bytes32

Pool sender must be operator of.

onlyDelegateCall

modifier onlyDelegateCall()

createStakingPool

function createStakingPool(address rigoblockPoolAddress) external returns (bytes32 poolId)

Create a new staking pool. The sender will be the staking pal of this pool.

Note that a staking pal must be payable. When governance updates registry address, pools must be migrated to new registry, or this contract must query from both.

Parameters

NameTypeDescription

rigoblockPoolAddress

address

Adds rigoblock pool to the created staking pool for convenience if non-null.

Return Values

NameTypeDescription

poolId

bytes32

The unique pool id generated for this pool.

setStakingPalAddress

function setStakingPalAddress(bytes32 poolId, address newStakingPalAddress) external

Allows the operator to update the staking pal address.

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

newStakingPalAddress

address

Address of the new staking pal.

decreaseStakingPoolOperatorShare

function decreaseStakingPoolOperatorShare(bytes32 poolId, uint32 newOperatorShare) external

Decreases the operator share for the given pool (i.e. increases pool rewards for members).

Parameters

NameTypeDescription

poolId

bytes32

Unique Id of pool.

newOperatorShare

uint32

The newly decreased percentage of any rewards owned by the operator.

getStakingPool

function getStakingPool(bytes32 poolId) public view returns (struct IStructs.Pool)

Returns a staking pool

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

_joinStakingPoolAsRbPoolAccount

function _joinStakingPoolAsRbPoolAccount(bytes32 _poold, address _rigoblockPoolAccount) internal

Allows caller to join a staking pool as a rigoblock pool account.

Parameters

NameTypeDescription

_poold

bytes32

Id of the pool.

_rigoblockPoolAccount

address

Address of pool to be added to staking pool.

_assertStakingPoolExists

function _assertStakingPoolExists(bytes32 poolId) internal view

Reverts iff a staking pool does not exist.

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

_assertStakingPoolDoesNotExist

function _assertStakingPoolDoesNotExist(bytes32 poolId) internal view

Reverts iff a staking pool does exist.

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

_assertSenderIsPoolOperator

function _assertSenderIsPoolOperator(bytes32 poolId) private view

Asserts that the sender is the operator of the input pool.

Parameters

NameTypeDescription

poolId

bytes32

Pool sender must be operator of.

_assertDelegateCall

function _assertDelegateCall() private view

Preventing direct calls to this contract where applied.

_assertNewOperatorShare

function _assertNewOperatorShare(uint32 currentOperatorShare, uint32 newOperatorShare) private pure

Reverts iff the new operator share is invalid.

Parameters

NameTypeDescription

currentOperatorShare

uint32

Current operator share.

newOperatorShare

uint32

New operator share.

MixinStakingPoolRewards

withdrawDelegatorRewards

function withdrawDelegatorRewards(bytes32 poolId) external

Withdraws the caller's GRG rewards that have accumulated until the last epoch.

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

computeRewardBalanceOfOperator

function computeRewardBalanceOfOperator(bytes32 poolId) external view returns (uint256 reward)

Computes the reward balance in GRG of the operator of a pool.

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

Return Values

NameTypeDescription

reward

uint256

Balance in GRG.

computeRewardBalanceOfDelegator

function computeRewardBalanceOfDelegator(bytes32 poolId, address member) external view returns (uint256 reward)

Computes the reward balance in GRG of a specific member of a pool.

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

member

address

The member of the pool.

Return Values

NameTypeDescription

reward

uint256

Balance in GRG.

_withdrawAndSyncDelegatorRewards

function _withdrawAndSyncDelegatorRewards(bytes32 poolId, address member) internal

Syncs rewards for a delegator. This includes withdrawing rewards rewards and adding/removing dependencies on cumulative rewards.

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

member

address

of the pool.

_syncPoolRewards

function _syncPoolRewards(bytes32 poolId, uint256 reward, uint256 membersStake) internal returns (uint256 operatorReward, uint256 membersReward)

Handles a pool's reward at the current epoch. This will split the reward between the operator and members, depositing them into their respective vaults, and update the accounting needed to allow members to withdraw their individual rewards.

Parameters

NameTypeDescription

poolId

bytes32

Unique Id of pool.

reward

uint256

received by the pool.

membersStake

uint256

the amount of non-operator delegated stake that will split the reward.

Return Values

NameTypeDescription

operatorReward

uint256

Portion of reward given to the pool operator.

membersReward

uint256

Portion of reward given to the pool members.

_computePoolRewardsSplit

function _computePoolRewardsSplit(uint32 operatorShare, uint256 totalReward, uint256 membersStake) internal pure returns (uint256 operatorReward, uint256 membersReward)

Compute the split of a pool reward between the operator and members based on the operatorShare and membersStake.

Parameters

NameTypeDescription

operatorShare

uint32

The fraction of rewards owed to the operator, in PPM.

totalReward

uint256

The pool reward.

membersStake

uint256

The amount of member (non-operator) stake delegated to the pool in the epoch the rewards were earned.

Return Values

NameTypeDescription

operatorReward

uint256

Portion of totalReward given to the pool operator.

membersReward

uint256

Portion of totalReward given to the pool members.

_computeDelegatorReward

function _computeDelegatorReward(bytes32 poolId, address member, uint256 unfinalizedMembersReward, uint256 unfinalizedMembersStake) private view returns (uint256 reward)

Computes the reward balance in ETH of a specific member of a pool.

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

member

address

of the pool.

unfinalizedMembersReward

uint256

Unfinalized total members reward (if any).

unfinalizedMembersStake

uint256

Unfinalized total members stake (if any).

Return Values

NameTypeDescription

reward

uint256

Balance in WETH.

_computeUnfinalizedDelegatorReward

function _computeUnfinalizedDelegatorReward(struct IStructs.StoredBalance delegatedStake, uint256 currentEpoch_, uint256 unfinalizedMembersReward, uint256 unfinalizedMembersStake) private pure returns (uint256)

Computes the unfinalized rewards earned by a delegator in the last epoch.

Parameters

NameTypeDescription

delegatedStake

struct IStructs.StoredBalance

Amount of stake delegated to pool by a specific staker

currentEpoch_

uint256

The epoch in which this call is executing

unfinalizedMembersReward

uint256

Unfinalized total members reward (if any).

unfinalizedMembersStake

uint256

Unfinalized total members stake (if any).

Return Values

NameTypeDescription

[0]

uint256

reward Balance in WETH.

_increasePoolRewards

function _increasePoolRewards(bytes32 poolId, uint256 amount) private

Increases rewards for a pool.

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

amount

uint256

Amount to increment rewards by.

_decreasePoolRewards

function _decreasePoolRewards(bytes32 poolId, uint256 amount) private

Decreases rewards for a pool.

Parameters

NameTypeDescription

poolId

bytes32

Unique id of pool.

amount

uint256

Amount to decrement rewards by.

MixinAbstract

Exposes some internal functions from various contracts to avoid cyclical dependencies.

_getUnfinalizedPoolRewards

function _getUnfinalizedPoolRewards(bytes32 poolId) internal view virtual returns (uint256 totalReward, uint256 membersStake)

Computes the reward owed to a pool during finalization. Does nothing if the pool is already finalized.

Parameters

NameTypeDescription

poolId

bytes32

The pool's ID.

Return Values

NameTypeDescription

totalReward

uint256

The total reward owed to a pool.

membersStake

uint256

The total stake for all non-operator members in this pool.

_assertPoolFinalizedLastEpoch

function _assertPoolFinalizedLastEpoch(bytes32 poolId) internal view virtual

Asserts that a pool has been finalized last epoch.

Parameters

NameTypeDescription

poolId

bytes32

The id of the pool that should have been finalized.

MixinFinalizer

endEpoch

function endEpoch() external returns (uint256 numPoolsToFinalize)

Begins a new epoch, preparing the prior one for finalization.

Throws if not enough time has passed between epochs or if the previous epoch was not fully finalized.

Return Values

NameTypeDescription

numPoolsToFinalize

uint256

The number of unfinalized pools.

finalizePool

function finalizePool(bytes32 poolId) external

Instantly finalizes a single pool that earned rewards in the previous epoch,

crediting it rewards for members and withdrawing operator's rewards as GRG. This can be called by internal functions that need to finalize a pool immediately. Does nothing if the pool is already finalized or did not earn rewards in the previous epoch.

Parameters

NameTypeDescription

poolId

bytes32

The pool ID to finalize.

_getUnfinalizedPoolRewards

function _getUnfinalizedPoolRewards(bytes32 poolId) internal view virtual returns (uint256 reward, uint256 membersStake)

Computes the reward owed to a pool during finalization. Does nothing if the pool is already finalized.

Parameters

NameTypeDescription

poolId

bytes32

The pool's ID.

Return Values

NameTypeDescription

reward

uint256

The total reward owed to a pool.

membersStake

uint256

The total stake for all non-operator members in this pool.

_getAvailableGrgBalance

function _getAvailableGrgBalance() internal view returns (uint256 grgBalance)

Returns the GRG balance of this contract, minus any GRG that has already been reserved for rewards.

_assertPoolFinalizedLastEpoch

function _assertPoolFinalizedLastEpoch(bytes32 poolId) internal view virtual

Asserts that a pool has been finalized last epoch.

Parameters

NameTypeDescription

poolId

bytes32

The id of the pool that should have been finalized.

_getUnfinalizedPoolRewardsFromPoolStats

function _getUnfinalizedPoolRewardsFromPoolStats(struct IStructs.PoolStats poolStats, struct IStructs.AggregatedStats aggregatedStats) private view returns (uint256 rewards)

Computes the reward owed to a pool during finalization.

Parameters

NameTypeDescription

poolStats

struct IStructs.PoolStats

Stats for a specific pool.

aggregatedStats

struct IStructs.AggregatedStats

Stats aggregated across all pools.

Return Values

NameTypeDescription

rewards

uint256

Unfinalized rewards for the input pool.

MixinParams

setParams

function setParams(uint256 _epochDurationInSeconds, uint32 _rewardDelegatedStakeWeight, uint256 _minimumPoolStake, uint32 _cobbDouglasAlphaNumerator, uint32 _cobbDouglasAlphaDenominator) external

Set all configurable parameters at once.

Parameters

NameTypeDescription

_epochDurationInSeconds

uint256

Minimum seconds between epochs.

_rewardDelegatedStakeWeight

uint32

How much delegated stake is weighted vs operator stake, in ppm.

_minimumPoolStake

uint256

Minimum amount of stake required in a pool to collect rewards.

_cobbDouglasAlphaNumerator

uint32

Numerator for cobb douglas alpha factor.

_cobbDouglasAlphaDenominator

uint32

Denominator for cobb douglas alpha factor.

getParams

function getParams() external view returns (uint256 _epochDurationInSeconds, uint32 _rewardDelegatedStakeWeight, uint256 _minimumPoolStake, uint32 _cobbDouglasAlphaNumerator, uint32 _cobbDouglasAlphaDenominator)

Retrieves all configurable parameter values.

Return Values

NameTypeDescription

_epochDurationInSeconds

uint256

Minimum seconds between epochs.

_rewardDelegatedStakeWeight

uint32

How much delegated stake is weighted vs operator stake, in ppm.

_minimumPoolStake

uint256

Minimum amount of stake required in a pool to collect rewards.

_cobbDouglasAlphaNumerator

uint32

Numerator for cobb douglas alpha factor.

_cobbDouglasAlphaDenominator

uint32

Denominator for cobb douglas alpha factor.

_initMixinParams

function _initMixinParams() internal

Initialize storage belonging to this mixin.

_assertParamsNotInitialized

function _assertParamsNotInitialized() internal view

Asserts that upgradable storage has not yet been initialized.

_setParams

function _setParams(uint256 _epochDurationInSeconds, uint32 _rewardDelegatedStakeWeight, uint256 _minimumPoolStake, uint32 _cobbDouglasAlphaNumerator, uint32 _cobbDouglasAlphaDenominator) private

Set all configurable parameters at once.

Parameters

NameTypeDescription

_epochDurationInSeconds

uint256

Minimum seconds between epochs.

_rewardDelegatedStakeWeight

uint32

How much delegated stake is weighted vs operator stake, in ppm.

_minimumPoolStake

uint256

Minimum amount of stake required in a pool to collect rewards.

_cobbDouglasAlphaNumerator

uint32

Numerator for cobb douglas alpha factor.

_cobbDouglasAlphaDenominator

uint32

Denominator for cobb douglas alpha factor.

MixinScheduler

getCurrentEpochEarliestEndTimeInSeconds

function getCurrentEpochEarliestEndTimeInSeconds() public view returns (uint256)

Returns the earliest end time in seconds of this epoch.

The next epoch can begin once this time is reached. Epoch period = [startTimeInSeconds..endTimeInSeconds)

Return Values

NameTypeDescription

[0]

uint256

Time in seconds.

_initMixinScheduler

function _initMixinScheduler() internal

Initializes state owned by this mixin. Fails if state was already initialized.

_goToNextEpoch

function _goToNextEpoch() internal

Moves to the next epoch, given the current epoch period has ended. Time intervals that are measured in epochs (like timeLocks) are also incremented, given their periods have ended.

_assertSchedulerNotInitialized

function _assertSchedulerNotInitialized() internal view

Assert scheduler state before initializing it. This must be updated for each migration.

Last updated