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

Name
Type
Description

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

_NIL_POOL_ID

_NIL_ADDRESS

_MIN_TOKEN_VALUE

MixinDeploymentConstants

constructor

_implementation

_rigoToken

_grgVault

_poolRegistry

getGrgContract

An overridable way to access the deployed GRG contract.

Must be view to allow overrides to access state.

Return Values

Name
Type
Description

[0]

contract IRigoToken

The GRG contract instance.

getGrgVault

An overridable way to access the deployed grgVault.

Must be view to allow overrides to access state.

Return Values

Name
Type
Description

[0]

contract IGrgVault

The GRG vault contract.

getPoolRegistry

An overridable way to access the deployed rigoblock pool registry.

Must be view to allow overrides to access state.

Return Values

Name
Type
Description

[0]

contract IPoolRegistry

The pool registry contract.

MixinStorage

stakingContract

Address of staking contract.

Return Values

_globalStakeByStatus

_ownerStakeByStatus

_delegatedStakeToPoolByOwner

_delegatedStakeByPoolId

poolIdByRbPoolAccount

Mapping from RigoBlock pool subaccount to pool Id of rigoblock pool

0 RigoBlock pool subaccount address.

Return Values

_poolById

rewardsByPoolId

mapping from pool ID to reward balance of members

0 Pool ID.

Return Values

currentEpoch

The current epoch.

Return Values

currentEpochStartTimeInSeconds

The current epoch start time.

Return Values

_cumulativeRewardsByPool

_cumulativeRewardsByPoolLastStored

validPops

Registered RigoBlock Proof_of_Performance contracts, capable of paying protocol fees.

0 The address to check.

Return Values

epochDurationInSeconds

Minimum seconds between epochs.

Return Values

rewardDelegatedStakeWeight

Return Values

minimumPoolStake

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

Return Values

cobbDouglasAlphaNumerator

Numerator for cobb douglas alpha factor.

Return Values

cobbDouglasAlphaDenominator

Denominator for cobb douglas alpha factor.

Return Values

poolStatsByEpoch

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

See _minimumPoolStake in MixinParams.

Parameters

Return Values

aggregatedStatsByEpoch

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

See _minimumPoolStake in MixinParams.

Parameters

Return Values

grgReservedForPoolRewards

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

Return Values

IGrgVault

StakingProxySet

Emmitted whenever a StakingProxy is set in a vault.

Parameters

Name
Type
Description

stakingProxyAddress

address

Address of the staking proxy contract.

InCatastrophicFailureMode

Emitted when the Staking contract is put into Catastrophic Failure Mode

Parameters

Name
Type
Description

sender

address

Address of sender (msg.sender)

Deposit

Emitted when Grg Tokens are deposited into the vault.

Parameters

Name
Type
Description

staker

address

Address of the Grg staker.

amount

uint256

of Grg Tokens deposited.

Withdraw

Emitted when Grg Tokens are withdrawn from the vault.

Parameters

Name
Type
Description

staker

address

Address of the Grg staker.

amount

uint256

of Grg Tokens withdrawn.

GrgProxySet

Emitted whenever the Grg AssetProxy is set.

Parameters

Name
Type
Description

grgProxyAddress

address

Address of the Grg transfer proxy.

setStakingProxy

Sets the address of the StakingProxy contract.

Note that only the contract staker can call this function.

Parameters

Name
Type
Description

stakingProxyAddress

address

Address of Staking proxy contract.

enterCatastrophicFailure

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

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

Name
Type
Description

grgProxyAddress

address

Address of the RigoBlock Grg Proxy.

depositFrom

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

Name
Type
Description

staker

address

Address of the Grg staker.

amount

uint256

of Grg Tokens to deposit.

withdrawFrom

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

Name
Type
Description

staker

address

Address of the Grg staker.

amount

uint256

of Grg Tokens to withdraw.

withdrawAllFrom

Withdraw ALL Grg Tokens to staker from the vault.

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

Parameters

Name
Type
Description

staker

address

Address of the Grg staker.

balanceOf

Returns the balance in Grg Tokens of the staker

Parameters

Name
Type
Description

staker

address

Address of the Grg staker.

Return Values

Name
Type
Description

[0]

uint256

Balance in Grg.

balanceOfGrgVault

Returns the entire balance of Grg tokens in the vault.

Return Values

Name
Type
Description

[0]

uint256

Balance in Grg.

IStaking

addPopAddress

Adds a new proof_of_performance address.

Parameters

Name
Type
Description

addr

address

Address of proof_of_performance contract to add.

createStakingPool

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

Name
Type
Description

rigoblockPoolAddress

address

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

Return Values

Name
Type
Description

poolId

bytes32

The unique pool id generated for this pool.

setStakingPalAddress

Allows the operator to update the staking pal address.

Parameters

Name
Type
Description

poolId

bytes32

Unique id of pool.

newStakingPalAddress

address

Address of the new staking pal.

decreaseStakingPoolOperatorShare

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

Parameters

Name
Type
Description

poolId

bytes32

Unique Id of pool.

newOperatorShare

uint32

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

endEpoch

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

Name
Type
Description

numPoolsToFinalize

uint256

The number of unfinalized pools.

finalizePool

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

Name
Type
Description

poolId

bytes32

The pool ID to finalize.

init

Initialize storage owned by this contract.

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

moveStake

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

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

Parameters

Name
Type
Description

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

Credits the value of a pool's pop reward.

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

Parameters

Name
Type
Description

poolAccount

address

The address of the rigoblock pool account.

popReward

uint256

The pop reward.

removePopAddress

Removes an existing proof_of_performance address.

Parameters

Name
Type
Description

addr

address

Address of proof_of_performance contract to remove.

setParams

Set all configurable parameters at once.

Parameters

Name
Type
Description

_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

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

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

Parameters

Name
Type
Description

amount

uint256

of GRG to stake.

unstake

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

Name
Type
Description

amount

uint256

of GRG to unstake.

withdrawDelegatorRewards

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

Parameters

Name
Type
Description

poolId

bytes32

Unique id of pool.

computeRewardBalanceOfDelegator

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

Parameters

Name
Type
Description

poolId

bytes32

Unique id of pool.

member

address

The member of the pool.

Return Values

Name
Type
Description

reward

uint256

Balance in GRG.

computeRewardBalanceOfOperator

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

Parameters

Name
Type
Description

poolId

bytes32

Unique id of pool.

Return Values

Name
Type
Description

reward

uint256

Balance in GRG.

getCurrentEpochEarliestEndTimeInSeconds

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

Name
Type
Description

[0]

uint256

Time in seconds.

getGlobalStakeByStatus

Gets global stake for a given status.

Parameters

Name
Type
Description

stakeStatus

enum IStructs.StakeStatus

UNDELEGATED or DELEGATED

Return Values

Name
Type
Description

balance

struct IStructs.StoredBalance

Global stake for given status.

getOwnerStakeByStatus

Gets an owner's stake balances by status.

Parameters

Name
Type
Description

staker

address

Owner of stake.

stakeStatus

enum IStructs.StakeStatus

UNDELEGATED or DELEGATED

Return Values

Name
Type
Description

balance

struct IStructs.StoredBalance

Owner's stake balances for given status.

getTotalStake

Returns the total stake for a given staker.

Parameters

Name
Type
Description

staker

address

of stake.

Return Values

Name
Type
Description

[0]

uint256

Total GRG staked by staker.

getParams

Retrieves all configurable parameter values.

Return Values

Name
Type
Description

_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

Returns stake delegated to pool by staker.

Parameters

Name
Type
Description

staker

address

of stake.

poolId

bytes32

Unique Id of pool.

Return Values

Name
Type
Description

balance

struct IStructs.StoredBalance

Stake delegated to pool by staker.

getStakingPool

Returns a staking pool

Parameters

Name
Type
Description

poolId

bytes32

Unique id of pool.

getStakingPoolStatsThisEpoch

Get stats on a staking pool in this epoch.

Parameters

Name
Type
Description

poolId

bytes32

Pool Id to query.

Return Values

Name
Type
Description

[0]

struct IStructs.PoolStats

PoolStats struct for pool id.

getTotalStakeDelegatedToPool

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

Parameters

Name
Type
Description

poolId

bytes32

Unique Id of pool.

Return Values

Name
Type
Description

balance

struct IStructs.StoredBalance

Total stake delegated to pool.

getGrgContract

An overridable way to access the deployed GRG contract.

Must be view to allow overrides to access state.

Return Values

Name
Type
Description

[0]

contract IRigoToken

The GRG contract instance.

getGrgVault

An overridable way to access the deployed grgVault.

Must be view to allow overrides to access state.

Return Values

Name
Type
Description

[0]

contract IGrgVault

The GRG vault contract.

getPoolRegistry

An overridable way to access the deployed rigoblock pool registry.

Must be view to allow overrides to access state.

Return Values

Name
Type
Description

[0]

contract IPoolRegistry

The pool registry contract.

IStakingEvents

Stake

Emitted by MixinStake when GRG is staked.

Parameters

Name
Type
Description

staker

address

of GRG.

amount

uint256

of GRG staked.

Unstake

Emitted by MixinStake when GRG is unstaked.

Parameters

Name
Type
Description

staker

address

of GRG.

amount

uint256

of GRG unstaked.

MoveStake

Emitted by MixinStake when GRG is unstaked.

Parameters

Name
Type
Description

staker

address

of GRG.

amount

uint256

of GRG unstaked.

fromStatus

uint8

fromPool

bytes32

toStatus

uint8

toPool

bytes32

PopAdded

Emitted by MixinExchangeManager when an exchange is added.

Parameters

Name
Type
Description

exchangeAddress

address

Address of new exchange.

PopRemoved

Emitted by MixinExchangeManager when an exchange is removed.

Parameters

Name
Type
Description

exchangeAddress

address

Address of removed exchange.

StakingPoolEarnedRewardsInEpoch

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

Parameters

Name
Type
Description

epoch

uint256

The epoch in which the pool earned rewards.

poolId

bytes32

The ID of the pool.

EpochEnded

Emitted by MixinFinalizer when an epoch has ended.

Parameters

Name
Type
Description

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

Emitted by MixinFinalizer when an epoch is fully finalized.

Parameters

Name
Type
Description

epoch

uint256

The epoch being finalized.

rewardsPaid

uint256

Total amount of rewards paid out.

rewardsRemaining

uint256

Rewards left over.

RewardsPaid

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

Parameters

Name
Type
Description

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

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

Parameters

Name
Type
Description

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

Emitted by MixinStakingPool when a new pool is created.

Parameters

Name
Type
Description

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

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

Parameters

Name
Type
Description

rbPoolAddress

address

Adress of maker added to pool.

poolId

bytes32

Unique id of pool.

OperatorShareDecreased

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

Parameters

Name
Type
Description

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

Emitted when an inflation mint call is executed successfully.

Parameters

Name
Type
Description

grgAmount

uint256

Amount of GRG tokens minted to the staking proxy.

CatchStringEvent

Emitted whenever an inflation mint call is reverted.

Parameters

Name
Type
Description

reason

string

String of the revert message.

ReturnDataEvent

Emitted to catch any other inflation mint call fail.

Parameters

Name
Type
Description

reason

bytes

Bytes output of the reverted transaction.

IStakingProxy

StakingContractAttachedToProxy

Emitted by StakingProxy when a staking contract is attached.

Parameters

Name
Type
Description

newStakingContractAddress

address

Address of newly attached staking contract.

StakingContractDetachedFromProxy

Emitted by StakingProxy when a staking contract is detached.

attachStakingContract

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

Note that this is callable only by an authorized address.

Parameters

Name
Type
Description

stakingImplementation

address

Address of staking contract.

detachStakingContract

Detach the current staking contract.

Note that this is callable only by an authorized address.

batchExecute

Batch executes a series of calls to the staking contract.

Parameters

Name
Type
Description

data

bytes[]

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

assertValidStorageParams

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

Address of staking contract.

Return Values

Name
Type
Description

[0]

address

stakingContract Address of the staking contract.

poolIdByRbPoolAccount

Mapping from RigoBlock pool subaccount to pool Id of rigoblock pool

0 RigoBlock pool subaccount address.

Return Values

Name
Type
Description

[0]

bytes32

0 The pool ID.

rewardsByPoolId

mapping from pool ID to reward balance of members

0 Pool ID.

Return Values

Name
Type
Description

[0]

uint256

0 The total reward balance of members in this pool.

currentEpoch

The current epoch.

Return Values

Name
Type
Description

[0]

uint256

currentEpoch The number of the current epoch.

currentEpochStartTimeInSeconds

The current epoch start time.

Return Values

Name
Type
Description

[0]

uint256

currentEpochStartTimeInSeconds Timestamp of start time.

validPops

Registered RigoBlock Proof_of_Performance contracts, capable of paying protocol fees.

0 The address to check.

Return Values

Name
Type
Description

[0]

bool

0 Whether the address is a registered proof_of_performance.

epochDurationInSeconds

Minimum seconds between epochs.

Return Values

Name
Type
Description

[0]

uint256

epochDurationInSeconds Number of seconds.

rewardDelegatedStakeWeight

Return Values

Name
Type
Description

[0]

uint32

rewardDelegatedStakeWeight Number in units of a million.

minimumPoolStake

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

Return Values

Name
Type
Description

[0]

uint256

minimumPoolStake Minimum amount required.

cobbDouglasAlphaNumerator

Numerator for cobb douglas alpha factor.

Return Values

Name
Type
Description

[0]

uint32

cobbDouglasAlphaNumerator Number of the numerator.

cobbDouglasAlphaDenominator

Denominator for cobb douglas alpha factor.

Return Values

Name
Type
Description

[0]

uint32

cobbDouglasAlphaDenominator Number of the denominator.

poolStatsByEpoch

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

See _minimumPoolStake in MixinParams.

Parameters

Name
Type
Description

key

bytes32

Pool ID.

epoch

uint256

Epoch number.

Return Values

Name
Type
Description

feesCollected

uint256

Amount of fees collected in epoch.

weightedStake

uint256

Weighted stake per million.

membersStake

uint256

Members stake per million.

aggregatedStatsByEpoch

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

See _minimumPoolStake in MixinParams.

Parameters

Name
Type
Description

epoch

uint256

Epoch number.

Return Values

Name
Type
Description

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

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

Return Values

Name
Type
Description

[0]

uint256

grgReservedForPoolRewards Number of tokens reserved for rewards.

IStorageInit

init

Initialize storage owned by this contract.

IStructs

PoolStats

AggregatedStats

StoredBalance

StakeStatus

StakeInfo

Fraction

Pool

LibCobbDouglas

cobbDouglas

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

Name
Type
Description

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

Name
Type
Description

rewards

uint256

Rewards owed to the staking pool.

LibFixedMath

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

FIXED_1

MIN_FIXED_VAL

FIXED_1_SQUARED

LN_MAX_VAL

LN_MIN_VAL

EXP_MAX_VAL

EXP_MIN_VAL

mul

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

div

Returns the division of two fixed point numbers.

mulDiv

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

uintMul

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

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

ln

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

exp

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

_mul

Returns the multiplication two numbers, reverting on overflow.

_div

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

LibSafeDowncast

downcastToUint96

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

downcastToUint64

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

MixinPopManager

addPopAddress

Adds a new proof_of_performance address.

Parameters

Name
Type
Description

addr

address

Address of proof_of_performance contract to add.

removePopAddress

Removes an existing proof_of_performance address.

Parameters

Name
Type
Description

addr

address

Address of proof_of_performance contract to remove.

MixinPopRewards

onlyPop

Asserts that the call is coming from a valid pop.

creditPopReward

Credits the value of a pool's pop reward.

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

Parameters

Name
Type
Description

poolAccount

address

The address of the rigoblock pool account.

popReward

uint256

The pop reward.

getStakingPoolStatsThisEpoch

Get stats on a staking pool in this epoch.

Parameters

Name
Type
Description

poolId

bytes32

Pool Id to query.

Return Values

Name
Type
Description

[0]

struct IStructs.PoolStats

PoolStats struct for pool id.

_computeMembersAndWeightedStake

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

Parameters

Name
Type
Description

poolId

bytes32

ID of the pool.

totalStake

uint256

Total (unweighted) stake in the pool.

Return Values

Name
Type
Description

membersStake

uint256

Non-operator stake in the pool.

weightedStake

uint256

Weighted stake of the pool.

MixinStake

stake

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

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

Parameters

Name
Type
Description

amount

uint256

of GRG to stake.

unstake

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

Name
Type
Description

amount

uint256

of GRG to unstake.

moveStake

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

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

Parameters

Name
Type
Description

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

Delegates a owners stake to a staking pool.

Parameters

Name
Type
Description

poolId

bytes32

Id of pool to delegate to.

staker

address

Owner who wants to delegate.

amount

uint256

Amount of stake to delegate.

_undelegateStake

Un-Delegates a owners stake from a staking pool.

Parameters

Name
Type
Description

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

Gets global stake for a given status.

Parameters

Name
Type
Description

stakeStatus

enum IStructs.StakeStatus

UNDELEGATED or DELEGATED

Return Values

Name
Type
Description

balance

struct IStructs.StoredBalance

Global stake for given status.

getOwnerStakeByStatus

Gets an owner's stake balances by status.

Parameters

Name
Type
Description

staker

address

Owner of stake.

stakeStatus

enum IStructs.StakeStatus

UNDELEGATED or DELEGATED

Return Values

Name
Type
Description

balance

struct IStructs.StoredBalance

Owner's stake balances for given status.

getTotalStake

Returns the total stake for a given staker.

Parameters

Name
Type
Description

staker

address

of stake.

Return Values

Name
Type
Description

[0]

uint256

Total GRG staked by staker.

getStakeDelegatedToPoolByOwner

Returns stake delegated to pool by staker.

Parameters

Name
Type
Description

staker

address

of stake.

poolId

bytes32

Unique Id of pool.

Return Values

Name
Type
Description

balance

struct IStructs.StoredBalance

Stake delegated to pool by staker.

getTotalStakeDelegatedToPool

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

Parameters

Name
Type
Description

poolId

bytes32

Unique Id of pool.

Return Values

Name
Type
Description

balance

struct IStructs.StoredBalance

Total stake delegated to pool.

MixinStakeStorage

This mixin contains logic for managing stake storage.

_moveStake

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

Parameters

Name
Type
Description

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

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

Parameters

Name
Type
Description

balancePtr

struct IStructs.StoredBalance

to load.

Return Values

Name
Type
Description

balance

struct IStructs.StoredBalance

current balance.

_increaseCurrentAndNextBalance

Increments both the current and next fields.

Parameters

Name
Type
Description

balancePtr

struct IStructs.StoredBalance

storage pointer to balance.

amount

uint256

to mint.

_decreaseCurrentAndNextBalance

Decrements both the current and next fields.

Parameters

Name
Type
Description

balancePtr

struct IStructs.StoredBalance

storage pointer to balance.

amount

uint256

to mint.

_increaseNextBalance

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

Parameters

Name
Type
Description

balancePtr

struct IStructs.StoredBalance

storage pointer to balance.

amount

uint256

to increment by.

_decreaseNextBalance

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

Parameters

Name
Type
Description

balancePtr

struct IStructs.StoredBalance

storage pointer to balance.

amount

uint256

to decrement by.

_storeBalance

Stores a balance in storage.

Parameters

Name
Type
Description

balancePtr

struct IStructs.StoredBalance

points to where balance will be stored.

balance

struct IStructs.StoredBalance

to save to storage.

_arePointersEqual

Returns true iff storage pointers resolve to same storage location.

Parameters

Name
Type
Description

balancePtrA

struct IStructs.StoredBalance

first storage pointer.

balancePtrB

struct IStructs.StoredBalance

second storage pointer.

Return Values

Name
Type
Description

areEqual

bool

true iff pointers are equal.

MixinCumulativeRewards

_isCumulativeRewardSet

returns true iff Cumulative Rewards are set

_addCumulativeReward

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

Name
Type
Description

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

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

Name
Type
Description

poolId

bytes32

The pool ID.

_computeMemberRewardOverInterval

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

Parameters

Name
Type
Description

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

Name
Type
Description

reward

uint256

Reward accumulated over interval [beginEpoch, endEpoch]

_getCumulativeRewardAtEpoch

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

Name
Type
Description

poolId

bytes32

Unique ID of pool.

epoch

uint256

The epoch to find the

Return Values

Name
Type
Description

cumulativeReward

struct IStructs.Fraction

The cumulative reward for poolId at epoch.

MixinStakingPool

onlyStakingPoolOperator

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

Parameters

Name
Type
Description

poolId

bytes32

Pool sender must be operator of.

onlyDelegateCall

createStakingPool

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

Name
Type
Description

rigoblockPoolAddress

address

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

Return Values

Name
Type
Description

poolId

bytes32

The unique pool id generated for this pool.

setStakingPalAddress

Allows the operator to update the staking pal address.

Parameters

Name
Type
Description

poolId

bytes32

Unique id of pool.

newStakingPalAddress

address

Address of the new staking pal.

decreaseStakingPoolOperatorShare

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

Parameters

Name
Type
Description

poolId

bytes32

Unique Id of pool.

newOperatorShare

uint32

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

getStakingPool

Returns a staking pool

Parameters

Name
Type
Description

poolId

bytes32

Unique id of pool.

_joinStakingPoolAsRbPoolAccount

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

Parameters

Name
Type
Description

_poold

bytes32

Id of the pool.

_rigoblockPoolAccount

address

Address of pool to be added to staking pool.

_assertStakingPoolExists

Reverts iff a staking pool does not exist.

Parameters

Name
Type
Description

poolId

bytes32

Unique id of pool.

_assertStakingPoolDoesNotExist

Reverts iff a staking pool does exist.

Parameters

Name
Type
Description

poolId

bytes32

Unique id of pool.

_assertSenderIsPoolOperator

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

Parameters

Name
Type
Description

poolId

bytes32

Pool sender must be operator of.

_assertDelegateCall

Preventing direct calls to this contract where applied.

_assertNewOperatorShare

Reverts iff the new operator share is invalid.

Parameters

Name
Type
Description

currentOperatorShare

uint32

Current operator share.

newOperatorShare

uint32

New operator share.

MixinStakingPoolRewards

withdrawDelegatorRewards

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

Parameters

Name
Type
Description

poolId

bytes32

Unique id of pool.

computeRewardBalanceOfOperator

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

Parameters

Name
Type
Description

poolId

bytes32

Unique id of pool.

Return Values

Name
Type
Description

reward

uint256

Balance in GRG.

computeRewardBalanceOfDelegator

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

Parameters

Name
Type
Description

poolId

bytes32

Unique id of pool.

member

address

The member of the pool.

Return Values

Name
Type
Description

reward

uint256

Balance in GRG.

_withdrawAndSyncDelegatorRewards

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

Parameters

Name
Type
Description

poolId

bytes32

Unique id of pool.

member

address

of the pool.

_syncPoolRewards

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

Name
Type
Description

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

Name
Type
Description

operatorReward

uint256

Portion of reward given to the pool operator.

membersReward

uint256

Portion of reward given to the pool members.

_computePoolRewardsSplit

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

Parameters

Name
Type
Description

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

Name
Type
Description

operatorReward

uint256

Portion of totalReward given to the pool operator.

membersReward

uint256

Portion of totalReward given to the pool members.

_computeDelegatorReward

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

Parameters

Name
Type
Description

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

Name
Type
Description

reward

uint256

Balance in WETH.

_computeUnfinalizedDelegatorReward

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

Parameters

Name
Type
Description

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

Name
Type
Description

[0]

uint256

reward Balance in WETH.

_increasePoolRewards

Increases rewards for a pool.

Parameters

Name
Type
Description

poolId

bytes32

Unique id of pool.

amount

uint256

Amount to increment rewards by.

_decreasePoolRewards

Decreases rewards for a pool.

Parameters

Name
Type
Description

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

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

Parameters

Name
Type
Description

poolId

bytes32

The pool's ID.

Return Values

Name
Type
Description

totalReward

uint256

The total reward owed to a pool.

membersStake

uint256

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

_assertPoolFinalizedLastEpoch

Asserts that a pool has been finalized last epoch.

Parameters

Name
Type
Description

poolId

bytes32

The id of the pool that should have been finalized.

MixinFinalizer

endEpoch

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

Name
Type
Description

numPoolsToFinalize

uint256

The number of unfinalized pools.

finalizePool

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

Name
Type
Description

poolId

bytes32

The pool ID to finalize.

_getUnfinalizedPoolRewards

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

Parameters

Name
Type
Description

poolId

bytes32

The pool's ID.

Return Values

Name
Type
Description

reward

uint256

The total reward owed to a pool.

membersStake

uint256

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

_getAvailableGrgBalance

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

_assertPoolFinalizedLastEpoch

Asserts that a pool has been finalized last epoch.

Parameters

Name
Type
Description

poolId

bytes32

The id of the pool that should have been finalized.

_getUnfinalizedPoolRewardsFromPoolStats

Computes the reward owed to a pool during finalization.

Parameters

Name
Type
Description

poolStats

struct IStructs.PoolStats

Stats for a specific pool.

aggregatedStats

struct IStructs.AggregatedStats

Stats aggregated across all pools.

Return Values

Name
Type
Description

rewards

uint256

Unfinalized rewards for the input pool.

MixinParams

setParams

Set all configurable parameters at once.

Parameters

Name
Type
Description

_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

Retrieves all configurable parameter values.

Return Values

Name
Type
Description

_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

Initialize storage belonging to this mixin.

_assertParamsNotInitialized

Asserts that upgradable storage has not yet been initialized.

_setParams

Set all configurable parameters at once.

Parameters

Name
Type
Description

_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

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

Name
Type
Description

[0]

uint256

Time in seconds.

_initMixinScheduler

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

_goToNextEpoch

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

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

Last updated