Staking Protocoltransfersreward

TransferRewardMixerStorage

This library implementation ensembles Transfer Reward Explicit Facets enabling the configuration of campaings' reward packets that can encapsulate diverse asset types (e.g., ERC20, ERC1155 etc.), and facilitate the transfer of these reward packets.

AlreadyInitialized

error AlreadyInitialized()

Thrown when attempting to re-initialize.

InvalidRewardMixerInitDataLengths

error InvalidRewardMixerInitDataLengths(uint256 selectorsLength, uint256 supportedAssetTypeCodesLength)

Thrown at initializer when the lengths of selectors and rewardAssetTypeCodes do not match.

CampaignNotOnCreationStateForSetting

error CampaignNotOnCreationStateForSetting(uint256 campaignId)

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

InvalidRewardMixerSetterDataLengths

error InvalidRewardMixerSetterDataLengths(uint256 campaignInputDataLength, uint256 inputAssetTypeCodesLength)

Thrown at setter when the lengths of campaignRewardData and rewardAssetTypeCodes arrays do not match.

UnsupportedRewardAssetType

error UnsupportedRewardAssetType(uint256 unsupportedAssetTypeCode)

Thrown at setter when an unsupported asset type code is specified as reward for a campaign.

STORAGE_SLOT

bytes32 STORAGE_SLOT

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

FunctionSelectors

Struct containing selectors of setter & transfer functions implemented in a TransferReward Explicit Facet.

struct FunctionSelectors {
  bytes4 setterSelector;
  bytes4 transferSelector;
}

CampaignRewardAssetInfo

Struct containing the local codes for the asset types supported within reward packets of a staking campaign.

struct CampaignRewardAssetInfo {
  uint256[] activeRewardAssetTypeCodes;
}

Layout

Struct for managing information related to the Transfer Reward Mixer and campaigns configuration.

struct Layout {
  bool isInitialized;
  mapping(uint256 => bool) isRewardAssetTypeSupported;
  mapping(uint256 => bytes4) setterSelectorForAssetType;
  mapping(uint256 => bytes4) transferSelectorForAssetType;
  mapping(uint256 => struct TransferRewardMixerStorage.CampaignRewardAssetInfo) rewardTypesForCampaign;
}

layout

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

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

initTransferReward

function initTransferReward(struct TransferRewardMixerStorage.Layout l, bytes initTransferRewardData) internal returns (uint256[])

Initializes the TransferRewardMixerStorage by registering the selectors for the setter and transferReward functions of the supported TransferReward Explicit facets, along with code schema for representing the ERC types handled by these Explicit facets.

The selectors provided must belong to the TransferReward Explicit facets that will be used for constructing reward packets of campaigns and for transferring assets encapsulated within a campaing's reward packet.

Requirements:

  • The selectors and rewardAssetTypeCodes arrays must have the same length.

IMPORTANT:

  • The code schema for supported ERCs in campaigns' reward packets helps identify the asset type that each registered TransferReward Mixer facet handles. While the construction of this shcema is at the discreation of the Admin, it is advised to use the numerical suffix of the ERC standards (e.g., 20 for ERC20, 1155 for ERC1155 etc.) as codes for clarity and consistency.

  • The i-th member of the rewardAssetTypeCodes array should correspond to the i-th member of the selectors array.


Parameters

NameTypeDescription
lstruct TransferRewardMixerStorage.LayoutA reference to the Layout struct in storage.
initTransferRewardDatabytesThe ABI encoded data containing the following: - selectors: An array of FunctionSelectors structs, each with the setter and transferReward function selectors of the supported TransferReward Explicit facets. - rewardAssetTypeCodes: The code schema that identifies the ERC (asset type) each supported TransferReward Explicit facet hanldles.

setCampaignTransferRewards

function setCampaignTransferRewards(struct TransferRewardMixerStorage.Layout l, uint256 campaignId, bytes campaignTransferRewardsData) internal returns (uint256[])

Setter function for configuring the reward packet for the specified staking campaign.

This setter function configures the reward packet for a campaign, where any of the supported asset types can be included. For instance, if ERC20 and ERC1155 Transfer Reward Explicit facets are supported, a packet could be configured as follows:

{ 100 TokenA (ERC20), 20.5 tokenB (ERC20), 10 tokenC ID 2 (ERC1155), 5 tokenD ID 1 (ERC1155) }

The construction of the reward packet is at the discretion of the campaign creator, as any possible combination of the supported Transfer Reward Explicit facets can be employed. These explicit facets must be already registered via initTransferReward().

Setter functions are executed during the creation process of campaigns (see CampaignCreationSkeleton.sol).

Requirements:

  • The campaignRewardData and rewardAssetTypeCodes arrays must have the same length.

IMPORTANT:

  • The asset type codes specified in rewardAssetTypeCodes should be valid, meaning that they should already be registered in the TransferReward Mixer storage (see initTransferReward()).

  • The i-th member of the rewardAssetTypeCodes array should correspond to the i-th member of the campaignRewardData array. ----------------------------------------------------------------------------------------------------------------_

Parameters

NameTypeDescription
lstruct TransferRewardMixerStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
campaignTransferRewardsDatabytesThe ABI-encoded settings data containing the following: - campaignRewardData: An bytes array with the ABI encoded data to be consumed as input by the setter functions of the targeted TransferReward Explicit facets. - rewardAssetTypeCodes: A uint256 array with the respective configured codes indicating the targeted TransferReward Explicit facets to be used.

transferReward

function transferReward(struct TransferRewardMixerStorage.Layout l, uint256 campaignId, address from, address to, uint256 amountOfPackets) internal

Transfers the specified amount of a given campaign's reward packets from the from address to the to address.

This function iteratively executes the respective transferReward functions of all Reward Explicit facets associated with the reward packet.

Parameters

NameTypeDescription
lstruct TransferRewardMixerStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
fromaddressThe address from which the assets encapsulated by the specified number of reward packets to be transferred.
toaddressThe address to receive the assets encapsulated by the specified number of reward packets.
amountOfPacketsuint256The number of reward packets to account for.