RateBasedOpenRewardDistributionFacetStorage
This library manages the storage and logic for the Rate-Based Open Reward Distribution algorithm.
_This implementation is designed exclusively for no-lock campaigns and does not support instant stake rewards. Lock multipliers are also not applicable.
Rewards are calculated as the product of the respective reward rate(s) (i.e., campaignRate
),
and active period(s), and the virtual balance of positions.
IMPORTANT:
-
Rate-Based Reward Distribution Facets should only be used in conjuction with RewardMinter Facets for configuring reward assets in staking campaigns.
-
This implementation is designed for campaigns where positions are always unlockable and instant staking rewards are not featured. It does not support scenarios where stakeholders can lock their positions._
CampaignNotOnCreationStateForSetting
Thrown when a targeted campaign is not "On Creation" state, which is required at configurations.
InvalidZeroCampaignRate
Thrown when the campaign rate is set to 0, which is not allowed.
NotCampaignCreator
Thrown when an account not being the creator of a campaign attempts to change its reward rate.
STORAGE_SLOT
Unique identifier for the storage slot where the Layout struct is stored.
DIVIDER
Used to normalize values (e.g., rates) for calculations with up to 18 decimal precision.
Layout
Struct for managing campaign information.
CampaignInfo
Struct containing local information for a staking campaign.
NftInfo
layout
Retrieves a reference to the Layout struct stored at the slot specified by STORAGE_SLOT
unique identifier.
setCampaignRewardsDistribution
Sets the rewards distribution schedule (rate of rewards) for a specified campaign.
This function can only be called during the campaign's creation
(see CampaignCreationSkeleton.createCampaign()
).
Parameters
Name | Type | Description |
---|---|---|
l | struct RateBasedOpenRewardDistributionFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
campaignRewardsDistributionData | bytes | The ABI encoded data containing the reward rate to set. |
changeCampaignRate
Changes the rate of rewards for a specified campaign.
Records the current block.timestamp when the change is applied. This function can only be called by the creator of the targeted campaign.
Parameters
Name | Type | Description |
---|---|---|
l | struct RateBasedOpenRewardDistributionFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
newRate | uint256 | The new reward rate to be applied for the campaign (must be scaled with 1e18 at API level). |
applyStake
Creates a new staking position in the specified campaign.
If no amount multiplier is applied, virtualPacketsStaked
will be equal to packetsStaked
.
Parameters
Name | Type | Description |
---|---|---|
l | struct RateBasedOpenRewardDistributionFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
nftId | uint256 | The unique identifier of the NFT associated with the position. |
virtualPacketsStaked | uint256 | The number of staked (input) packets adjusted by the applicable amount multiplier. |
packetsStaked | uint256 | The raw number of staked packets, without accounting for amount multipliers. |
applyRestake
Called when a specified position in the given campaign is increased.
Records the index of the last snapshot for the given position.
Parameters
Name | Type | Description |
---|---|---|
l | struct RateBasedOpenRewardDistributionFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
nftId | uint256 | The unique identifier of the NFT associated with the position. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | 0 because unclaimed rewards (till restake) should be provided by getRestakeReward() (see facet). |
applyUnstake
Returns the claimable rewards for a position being unstaked (either partially or fully).
See getReward()
for details on reward calculation.
Parameters
Name | Type | Description |
---|---|---|
l | struct RateBasedOpenRewardDistributionFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
nftId | uint256 | The unique identifier of the NFT associated with the position. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | The calculated claimable rewards. |
getReward
Returns the claimable rewards for a specific position.
See _calculateReward()
for details on reward calculation.
Parameters
Name | Type | Description |
---|---|---|
l | struct RateBasedOpenRewardDistributionFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
nftId | uint256 | The unique identifier of the NFT associated with the position. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | The rewards that can be claimed by the specified position. |
_calculateReward
Calculates a given position's rewards based on the specified reward rate, and active duration.
This function assumes that the campaignRate
input value is scaled by 1e18.
Parameters
Name | Type | Description |
---|---|---|
campaignRate | uint256 | The reward rate to use (should be scaled by 1e18). |
nftId | uint256 | The unique identifier of the NFT associated with the position. |
activePeriod | uint256 | The duration for which the reward is calculated, expressed in seconds. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | The calculated reward for the specified parameters, scaled down by DIVIDER . |