Staking ProtocolrewardsDistributionrateBasedRewardDistributionrateBasedOpenRewardDistribution

RateBasedOpenRewardDistributionFacet

This facet manages the logic and storage for the Rate-Based Open Reward Distribution algorithm. The functions in this facet handle operations such as creating and increasing staking positions, and calculating claimable rewards based on amount multipliers.

This facet is designed exclusively for no-lock campaigns and does not support instant stake rewards, while maintaining flexibility for future updates and features.

_It operates using the Layout struct defined in RateBasedOpenRewardDistributionFacetStorage, which contains essential data for managing staking campaigns within the context of the Rate-Based rewards distribution schedule.

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.

  • Reward rates should be scaled by 1e18 at the API level, allowing for calculations with up to 18 decimal precision._

CampaignRewardsDistributionConfigured

event CampaignRewardsDistributionConfigured(uint256 campaignId, uint256 rewardRate)

Emitted at setCampaignRewardsDistribution().

RewardRateChanged

event RewardRateChanged(uint256 campaignId, uint256 newRewardRate)

Emitted at changeCampaignRate().

setCampaignRewardsDistribution

function setCampaignRewardsDistribution(uint256 campaignId, bytes campaignRewardsDistributionData) external

Sets the rewards distribution schedule for a specified campaign.

_This function can only be called during the campaign's creation (see CampaignCreationSkeleton.createCampaign()). The reward rate must be scaled by 1e18 (18 decimal precision support).

Emits a {CampaignRewardsDistributionConfigured} event.

IMPORTANT: Reward Rate value should be scaled by 1e18 at the API level, allowing for 18 decimal precision._

Parameters

NameTypeDescription
campaignIduint256The unique identifier of the targeted staking campaign.
campaignRewardsDistributionDatabytesThe ABI-encoded uint256 for the reward rate value to set.

changeCampaignRate

function changeCampaignRate(uint256 campaignId, uint256 newRate) external

Changes the rate of rewards for a specified campaign.

This function can only be called by the creator of the targeted campaign.

Parameters

NameTypeDescription
campaignIduint256The unique identifier of the targeted staking campaign.
newRateuint256The new reward rate to be applied for the campaign (must be scaled with 1e18).

applyStake

function applyStake(uint256 campaignId, uint256 nftId, uint256 virtualPacketsStaked, uint256 packetsStaked, address) external

Creates a new staking position in the specified campaign.

If no amount multiplier is applied, virtualPacketsStaked will be equal to packetsStaked.

Parameters

NameTypeDescription
campaignIduint256The unique identifier of the targeted staking campaign.
nftIduint256The unique identifier of the NFT associated with the position.
virtualPacketsStakeduint256The number of staked (input) packets adjusted by the applicable multiplier (if any).
packetsStakeduint256The raw number of staked packets, before applying any amount multiplier.
address

applyRestake

function applyRestake(uint256 campaignId, uint256 nftId) external returns (uint256)

Increases the given staking position in the specified campaign.

Parameters

NameTypeDescription
campaignIduint256The unique identifier of the targeted staking campaign (unused in this implementation).
nftIduint256The unique identifier of the NFT associated with the position (unused in this implementation).

Return Values

NameTypeDescription
[0]uint2560 since unclaimed rewards (till restake) should be provided by getRestakeReward()

applyUnstake

function applyUnstake(uint256 campaignId, uint256 nftId) external returns (uint256)

Called when a position's owner partially or fully unstakes.

Decreasing or closing a position (partially or fully unstaking) should be allowed at any time.

Parameters

NameTypeDescription
campaignIduint256The unique identifier of the targeted staking campaign.
nftIduint256The unique identifier of the NFT associated with the position.

Return Values

NameTypeDescription
[0]uint256The position's accured claimable rewards (output packets).

getReward

function getReward(uint256 campaignId, uint256 nftId) external returns (uint256)

Returns the accrued claimable rewards for a specific position.

Claimable rewards begin to accrue at the moment a position is created based on the campaign's reward distribution settings.

Parameters

NameTypeDescription
campaignIduint256The unique identifier of the targeted staking campaign.
nftIduint256The unique identifier of the NFT associated with the position.

Return Values

NameTypeDescription
[0]uint256The amount of reward packets that can be claimed by the specified position.

getRestakeReward

function getRestakeReward(uint256 campaignId, uint256 nftId) external returns (uint256)

Returns the accured claimable rewards for a specific position.

This function is called when a position is increased (see StakingSkeleton.sol).

Parameters

NameTypeDescription
campaignIduint256The unique identifier of the targeted staking campaign.
nftIduint256The unique identifier of the NFT associated with the position.

Return Values

NameTypeDescription
[0]uint256The amount of reward packets that can be claimed by the specified position.

On this page