PreStakeRewardDistributionFacetStorage
This library manages the storage and logic for the PreStake Reward Distribution algorithm.
_This implementation is designed exclusively for campaigns that expect users to stake (or restake) within a predefined time window, specifically between the campaign's starting and ending timestamps. Rewards are distributed only after the campaign's ending timestamp and up until a predefined rewards ending timestamp.
Key Design Features:
- Fixed Lock Period: All users should be locked for the same duration, eliminating the need for lock multipliers.
- Restaking is permitted only within the campaign's staking window (
startingTimestamp <= t_stake <= endingTimestamp
). - Delayed Rewards: Rewards are not distributed instantly upon staking but are available after the campaign's ending timestamp.
- InstaRewards Option:
- If enabled, users can claim all their designated rewards immediately after the campaign's ending timestamp, though they remain locked until the rewards ending timestamp.
- If disabled, users receive rewards proportionally based on the time elapsed since the campaign's ending timestamp. Full rewards are only claimable after the rewards ending timestamp.
Integration Considerations:
-
Using
ERC__RewardTransferFacet
:- Rewards are transferred from the distributor to the
RewardAssetHandler
. - The reward distributor must approve the diamond for reward transfers before the PreStake configuration is executed.
- The diamond contract will initiate
transferFrom
to retrieve the rewards.
- Rewards are transferred from the distributor to the
-
Using
ERC__RewardMinterFacet
:- Rewards are minted by the campaign's
RewardAssetHandler
, not the diamond itself. - The minter role must be assigned to the campaign's
RewardAssetHandler
._
- Rewards are minted by the campaign's
CampaignNotOnCreationStateForSetting
Thrown when a targeted campaign is not "On Creation" state, which is required at configurations.
InvalidZeroTotalReward
Thrown at setter when attempting to set 0 total rewards.
InvalidZeroRewardProviderAddress
Thrown at setter when the zero address is specified as the reward provider.
NoRewardsYet
Thrown at calculateReward()
when the campaign's reward period has not yet started.
STORAGE_SLOT
Unique identifier for the storage slot where the Layout struct is stored.
DIVIDER
Used to normalize values for calculations with up to 18 decimal precision.
Layout
Struct for managing campaign information.
CampaignInfo
Struct containing local information for a staking campaign.
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 creator.
(see CampaignCreationSkeleton.createCampaign()
).
Parameters
Name | Type | Description |
---|---|---|
l | struct PreStakeRewardDistributionFacetStorage.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. |
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 PreStakeRewardDistributionFacetStorage.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.
Parameters
Name | Type | Description |
---|---|---|
l | struct PreStakeRewardDistributionFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
uint256 |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | 0 because rewards are provided after ending timestamp of campaign. |
applyUnstake
Returns the claimable rewards for a position being unstaked.
Parameters
Name | Type | Description |
---|---|---|
l | struct PreStakeRewardDistributionFacetStorage.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 PreStakeRewardDistributionFacetStorage.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 active period, total stakes and stake of position.
Parameters
Name | Type | Description |
---|---|---|
l | struct PreStakeRewardDistributionFacetStorage.Layout | |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
nftId | uint256 | The unique identifier of the NFT associated with the position. |
rewardTimestamp | uint256 | The duration for which the reward is calculated, expressed in seconds. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | The calculated reward |