Staking ProtocolrewardsDistributioncomplexRewardDistribution

ComplexRewardDistributionFacetStorage

ComplexRewardDistributionFacetStorage

Complex Reward Distribution Facets should only be used in conjuction with RewardTransferrer Facets for configuring reward assets in staking campaigns.

CampaignNotOnCreationStateForSetting

error CampaignNotOnCreationStateForSetting(uint256 campaignId)

Thrown when a targeted campaign is not "On Creation" state, which is required at configurations.

InvalidZeroDuration

error InvalidZeroDuration(uint256 campaignId)

Thrown at setter when duration is attempted to be set as 0 value.

InvalidZeroAddressForRewardDistributor

error InvalidZeroAddressForRewardDistributor(uint256 campaignId)

Thrown at setter when rewardDistributor is attempted to be set as zero address.

OnlyRewardDistributor

error OnlyRewardDistributor(uint256 campaignId, address invalidCaller)

Thrown at notifyRewardAmount() when caller is not the campaign's designated reward distributor.

NoStakesToNotifyReward

error NoStakesToNotifyReward(uint256 campaignId)

Thrown at notifyRewardAmount() when the targeted campaign has zero staked assets.

STORAGE_SLOT

bytes32 STORAGE_SLOT

Unique identifier for the storage slot where the Layout struct is stored.

Layout

struct Layout {
  mapping(uint256 => struct ComplexRewardDistributionFacetStorage.CampaignInfo) campaignInfoLocal;
}

CampaignInfo

struct CampaignInfo {
  address rewardDistributor;
  uint256 lastTimeRewardApplied;
  uint256 updatedAt;
  uint256 periodFinish;
  uint256 duration;
  uint256 rewardRate;
  uint256 rewardPerTokenStored;
  mapping(uint256 => struct ComplexRewardDistributionFacetStorage.NftInfo) nftInfoLocal;
}

NftInfo

struct NftInfo {
  uint256 rewardPerTokenPaid;
  uint256 residual;
  uint256 rewardPacketsToBePaid;
}

layout

function layout() internal pure returns (struct ComplexRewardDistributionFacetStorage.Layout l)

Retrieves a reference to the Layout struct stored at the slot specified by STORAGE_SLOT unique identifier.

setCampaignRewardsDistribution

function setCampaignRewardsDistribution(struct ComplexRewardDistributionFacetStorage.Layout l, uint256 campaignId, bytes campaignRewardsDistributionData) internal returns (uint256, address)

Sets the rewards distribution schedule for a specified campaign.

_This function can only be called during the campaign's creation (see CampaignCreationSkeleton.createCampaign()).

Sets the duration and the designated reward distributor._

Parameters

NameTypeDescription
lstruct ComplexRewardDistributionFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
campaignRewardsDistributionDatabytesThe ABI-encoded data for the reward distribution schedule.

applyStake

function applyStake(struct ComplexRewardDistributionFacetStorage.Layout l, uint256 campaignId, uint256 nftId, uint256 virtualPacketsStaked, uint256 packetsStaked) internal

Creates a new staking position in the specified campaign.

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

Parameters

NameTypeDescription
lstruct ComplexRewardDistributionFacetStorage.LayoutA reference to the Layout struct in storage.
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 amount multiplier.
packetsStakeduint256The raw number of staked packets, without accounting for amount multipliers.

applyUnstake

function applyUnstake(struct ComplexRewardDistributionFacetStorage.Layout l, uint256 campaignId, uint256 nftId) internal returns (uint256)

Returns the claimable rewards for a position being unstaked.

Parameters

NameTypeDescription
lstruct ComplexRewardDistributionFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
nftIduint256The unique identifier of the NFT associated with the position.

Return Values

NameTypeDescription
[0]uint256The calculated claimable rewards.

getReward

function getReward(struct ComplexRewardDistributionFacetStorage.Layout l, uint256 campaignId, uint256 nftId) internal returns (uint256)

Returns the claimable rewards for a specific position.

Parameters

NameTypeDescription
lstruct ComplexRewardDistributionFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
nftIduint256The unique identifier of the NFT associated with the position.

Return Values

NameTypeDescription
[0]uint256The rewards that can be claimed by the specified position.

notifyRewardAmount

function notifyRewardAmount(struct ComplexRewardDistributionFacetStorage.Layout l, uint256 campaignId, uint256 rewardAmount) internal

This function is called by the reward distributor of the specified campaign to provide additional rewards.

This function can only be called by the reward distributor of the campaign.

Parameters

NameTypeDescription
lstruct ComplexRewardDistributionFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
rewardAmountuint256The amount of reward packets.

updateReward

function updateReward(struct ComplexRewardDistributionFacetStorage.Layout l, uint256 campaignId, uint256 nftId) internal

earned

function earned(struct ComplexRewardDistributionFacetStorage.Layout l, uint256 campaignId, uint256 nftId) internal returns (uint256)

lastTimeRewardApplicable

function lastTimeRewardApplicable(struct ComplexRewardDistributionFacetStorage.Layout l, uint256 campaignId) internal view returns (uint256)

_min

function _min(uint256 x, uint256 y) internal pure returns (uint256)

rewardPerToken

function rewardPerToken(struct ComplexRewardDistributionFacetStorage.Layout l, uint256 campaignId) internal view returns (uint256)