staking docs
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.
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. |
function init() public
Initialize storage owned by this contract.
This function should not be called directly. The StakingProxy contract will call it in
attachStakingContract()
.uint32 _PPM_DENOMINATOR
bytes32 _NIL_POOL_ID
address _NIL_ADDRESS
uint256 _MIN_TOKEN_VALUE
constructor(address grgVault, address poolRegistry, address rigoToken) internal
address _implementation
address _rigoToken
address _grgVault
address _poolRegistry
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.
Name | Type | Description |
---|---|---|
[0] | contract IRigoToken | The GRG contract instance. |
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.
Name | Type | Description |
---|---|---|
[0] | contract IGrgVault | The GRG vault contract. |
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.
Name | Type | Description |
---|---|---|
[0] | contract IPoolRegistry | The pool registry contract. |
address stakingContract
Address of staking contract.
mapping(uint8 => struct IStructs.StoredBalance) _globalStakeByStatus
mapping(uint8 => mapping(address => struct IStructs.StoredBalance)) _ownerStakeByStatus
mapping(address => mapping(bytes32 => struct IStructs.StoredBalance)) _delegatedStakeToPoolByOwner
mapping(bytes32 => struct IStructs.StoredBalance) _delegatedStakeByPoolId
mapping(address => bytes32) poolIdByRbPoolAccount
Mapping from RigoBlock pool subaccount to pool Id of rigoblock pool
0 RigoBlock pool subaccount address.
mapping(bytes32 => struct IStructs.Pool) _poolById
mapping(bytes32 => uint256) rewardsByPoolId
mapping from pool ID to reward balance of members
0 Pool ID.
uint256 currentEpoch
The current epoch.
uint256 currentEpochStartTimeInSeconds
The current epoch start time.
mapping(bytes32 => mapping(uint256 => struct IStructs.Fraction)) _cumulativeRewardsByPool
mapping(bytes32 => uint256) _cumulativeRewardsByPoolLastStored
mapping(address => bool) validPops
Registered RigoBlock Proof_of_Performance contracts, capable of paying protocol fees.
0 The address to check.
uint256 epochDurationInSeconds
Minimum seconds between epochs.
uint32 rewardDelegatedStakeWeight
uint256 minimumPoolStake
Minimum amount of stake required in a pool to collect rewards.
uint32 cobbDouglasAlphaNumerator
Numerator for cobb douglas alpha factor.
uint32 cobbDouglasAlphaDenominator
Denominator for cobb douglas alpha factor.
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
.mapping(uint256 => struct IStructs.AggregatedStats) aggregatedStatsByEpoch
Aggregated stats across all pools that generated fees with sufficient stake to earn rewards.
See
_minimumPoolStake
in MixinParams.uint256 grgReservedForPoolRewards
The GRG balance of this contract that is reserved for pool reward payouts.
event StakingProxySet(address stakingProxyAddress)
Emmitted whenever a StakingProxy is set in a vault.
Name | Type | Description |
---|---|---|
stakingProxyAddress | address | Address of the staking proxy contract. |
event InCatastrophicFailureMode(address sender)
Emitted when the Staking contract is put into Catastrophic Failure Mode
Name | Type | Description |
---|---|---|
sender | address | Address of sender ( msg.sender ) |
event Deposit(address staker, uint256 amount)
Emitted when Grg Tokens are deposited into the vault.
Name | Type | Description |
---|---|---|
staker | address | Address of the Grg staker. |
amount | uint256 | of Grg Tokens deposited. |
event Withdraw(address staker, uint256 amount)
Emitted when Grg Tokens are withdrawn from the vault.
Name | Type | Description |
---|---|---|
staker | address | Address of the Grg staker. |
amount | uint256 | of Grg Tokens withdrawn. |
event GrgProxySet(address grgProxyAddress)
Emitted whenever the Grg AssetProxy is set.
Name | Type | Description |
---|---|---|
grgProxyAddress | address | Address of the Grg transfer proxy. |
function setStakingProxy(address stakingProxyAddress) external
Sets the address of the StakingProxy contract.
Note that only the contract staker can call this function.
Name | Type | Description |
---|---|---|
stakingProxyAddress | address | Address of Staking proxy contract. |
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.
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.
Name | Type | Description |
---|---|---|
grgProxyAddress | address | Address of the RigoBlock Grg Proxy. |
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.
Name | Type | Description |
---|---|---|
staker | address | Address of the Grg staker. |
amount | uint256 | of Grg Tokens to deposit. |
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.
Name | Type | Description |
---|---|---|
staker | address | Address of the Grg staker. |
amount | uint256 | of Grg Tokens to withdraw. |
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.
Name | Type | Description |
---|---|---|
staker | address | Address of the Grg staker. |
function balanceOf(address staker) external view returns (uint256)
Returns the balance in Grg Tokens of the
staker
Name | Type | Description |
---|---|---|
staker | address | Address of the Grg staker. |
Name | Type | Description |
---|---|---|
[0] | uint256 | Balance in Grg. |
function balanceOfGrgVault() external view returns (uint256)
Returns the entire balance of Grg tokens in the vault.
Name | Type | Description |
---|---|---|
[0] | uint256 | Balance in Grg. |
function addPopAddress(address addr) external
Adds a new proof_of_performance address.
Name | Type | Description |
---|---|---|
addr | address | Address of proof_of_performance contract to add. |
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.
Name | Type | Description |
---|---|---|
rigoblockPoolAddress | address | Adds rigoblock pool to the created staking pool for convenience if non-null. |
Name | Type | Description |
---|---|---|
poolId | bytes32 | The unique pool id generated for this pool. |
function setStakingPalAddress(bytes32 poolId, address newStakingPalAddress) external
Allows the operator to update the staking pal address.
Name | Type | Description |
---|---|---|
poolId | bytes32 | Unique id of pool. |
newStakingPalAddress | address | Address of the new staking pal. |
function decreaseStakingPoolOperatorShare(bytes32 poolId, uint32 newOperatorShare) external
Decreases the operator share for the given pool (i.e. increases pool rewards for members).
Name | Type | Description |
---|---|---|
poolId | bytes32 | Unique Id of pool. |
newOperatorShare | uint32 | The newly decreased percentage of any rewards owned by the operator. |
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.
Name | Type | Description |
---|---|---|
numPoolsToFinalize | uint256 | The number of unfinalized pools. |
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.
Name | Type | Description |
---|---|---|
poolId | bytes32 | The pool ID to finalize. |
function init() external
Initialize storage owned by this contract.
This function should not be called directly. The StakingProxy contract will call it in
attachStakingContract()
.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.
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. |
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).
Name | Type | Description |
---|---|---|
poolAccount | address | The address of the rigoblock pool account. |
popReward | uint256 | The pop reward. |
function removePopAddress(address addr) external
Removes an existing proof_of_performance address.
Name | Type | Description |
---|---|---|
addr | address | Address of proof_of_performance contract to remove. |
function setParams(uint256 _epochDurationInSeconds, uint32 _rewardDelegatedStakeWeight, uint256 _minimumPoolStake, uint32 _cobbDouglasAlphaNumerator, uint32 _cobbDouglasAlphaDenominator) external
Set all configurable parameters at once.
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. |
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.
Name | Type | Description |
---|---|---|
amount | uint256 | of GRG to stake. |
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.
Name | Type | Description |
---|---|---|
amount | uint256 | of GRG to unstake. |
function withdrawDelegatorRewards(bytes32 poolId) external
Withdraws the caller's GRG rewards that have accumulated until the last epoch.