Erc1155RewardTransferFacetStorage
This library manages the storage and logic for handling the configuration of reward (output) packets for staking campaigns and facilitates their transfer.
_This implementation is specifically designed for staking campaigns where the reward packet is constructed solely from ERC1155 tokens, and where the campaign's reward asset handler is expected to have sufficient balance of the ERC1155 assets specified in the reward packet.
IMPORTANT:
- A reward packet can encapsulate one (e.g., tokenA of ID X) or more (e.g., tokenA of ID X, tokenA of ID Y, ..., tokenX of ID Z) ERC1155 tokens._
CampaignNotOnCreationStateForSetting
Thrown when a targeted campaign is not "On Creation" state, which is required at configurations.
NoRewardPacketDataProvided
Thrown at setter when no data provided for either tokenAddresses
or tokenIds
or amountOfTokensPerPacket
.
InvalidRewardPacketDataLengths
Thrown at setter when the lengths of tokenAddresses
, tokenIds
and amountOfTokensPerPacket
do not match.
InvalidZeroRewardPacketAddressData
Thrown at setter when an element of tokenAddresses
is the zero address.
InvalidZeroRewardPacketAmountData
Thrown at setter when an element of amountOfTokensPerPacket
is zero.
STORAGE_SLOT
Unique identifier for the storage slot where the Layout struct is stored.
Layout
Struct for managing information related to campaigns' reward packets.
RewardPacket
Struct containing the configuration information for a reward packet.
layout
Retrieves a reference to the Layout struct stored at the slot specified by STORAGE_SLOT
unique identifier.
setCampaignTransferRewards
Setter function for configuring the reward packet for the specified staking campaign.
_Setter functions are executed during the creation process of campaigns (see CampaignCreationSkeleton.sol
).
This setter function configures the reward packet for a campaign, where only ERC1155 tokens should be included.
Requirements:
- The
tokenAddresses
,tokenIds
andamountOfTokensPerPacket
arrays must have the same length. tokenAddresses
must contain valid, non-zero ERC1155 token addresses.amountOfTokensPerPacket
must contain non-zero values.
IMPORTANT:
- When using this facet, the campaign's reward asset handler must have sufficient balances of the ERC1155
assets specified in
tokenAddresses
, else the campaign will fail to provide the appropriate rewards. ----------------------------------------------------------------------------------------------------------------_
Parameters
Name | Type | Description |
---|---|---|
l | struct Erc1155RewardTransferFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
campaignTransferRewardsData | bytes | The ABI-encoded data containing the following: - tokenAddresses : An address array containing the addresses of the ERC1155 tokens encapsulated by the reward packet. - tokenIds : A uint256 array specifying the ID for each corresponding token in tokenAddresses . - amountOfTokensPerPacket : A uint256 array specifying the amount for each corresponding token in tokenAddresses . |
transferReward
Transfers the specified amount of a given campaign's reward packets from the from
address
to the to
address.
_This function iteratively executes transfer functions for all respective amounts of ERC1155 tokens defined
in the campaign's reward packet (see setCampaignTransferRewards()
) in a single transaction.
The amounts to be transferred are calculated as
amountOfTokensPerPacket[i] * amountOfPackets
for each token in the reward packet, where i
is the index of the token in the tokenAddresses
array. The transfer is performed using
the safeTransferFrom
method of the ERC1155 token interface._
Parameters
Name | Type | Description |
---|---|---|
l | struct Erc1155RewardTransferFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
from | address | The address from which the ERC1155 assets encapsulated by the specified number of rewards packets to be transferred. |
to | address | The address to receive the ERC1155 assets encapsulated by the specified number of reward packets. |
amountOfPackets | uint256 | The number of reward packets to account for. |