Staking ProtocolinternalFacetstransfersrewarderc20minter

Erc20RewardMinterFacetStorage

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 ERC20 tokens, and where the staking platform (i.e., the diamond) holds the minter role or has minting privileges on these token contracts.

IMPORTANT:

  • A reward packet can encapsulate one (e.g., tokenA) or more (e.g., tokenA, tokenB, ..., tokenX) ERC20 tokens.

NOTE: Although rewards are minted by the platform and not transferred in this context, the "transfer" terminology is used in the function transferReward() to comply with the ITransferRewardFacet.sol interface. This maintains a consistent interface for reward handling across facets and allows seamless integration with StakingSkeleton.sol._

CampaignNotOnCreationStateForSetting

error CampaignNotOnCreationStateForSetting(uint256 campaignId)

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

NoRewardPacketDataProvided

error NoRewardPacketDataProvided(uint256 campaignId)

Thrown at setter when no data provided for either tokenAddresses or amountOfTokensPerPacket.

InvalidRewardPacketDataLengths

error InvalidRewardPacketDataLengths(uint256 campaignId, uint256 tokenAddressesLength, uint256 amountOfTokensPerPacketLength)

Thrown at setter when the lengths of tokenAddresses and amountOfTokensPerPacket do not match.

InvalidZeroRewardPacketAddressData

error InvalidZeroRewardPacketAddressData(uint256 campaignId, uint256 index)

Thrown at setter when an element of tokenAddresses is the zero address.

InvalidZeroRewardPacketAmountData

error InvalidZeroRewardPacketAmountData(uint256 campaignId, uint256 index)

Thrown at setter when an element of amountOfTokensPerPacket is zero.

STORAGE_SLOT

bytes32 STORAGE_SLOT

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

Layout

Struct for managing information related to campaigns' reward packets.

struct Layout {
  mapping(uint256 => struct Erc20RewardMinterFacetStorage.RewardPacket) campaignsPacketInfo;
}

RewardPacket

Struct containing the configuration information for a reward packet.

struct RewardPacket {
  address[] tokenAddresses;
  mapping(address => uint256) amountOfTokensPerPacket;
}

layout

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

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

setCampaignTransferRewards

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

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 ERC20 tokens should be included.

Requirements:

  • The tokenAddresses and amountOfTokensPerPacket arrays must have the same length.
  • tokenAddresses must contain valid, non-zero ERC20 token addresses.
  • amountOfTokensPerPacket must contain non-zero values.

IMPORTANT:

  • When using this implementation, the campaign's reward asset handler must have minter privileges on all the ERC20 token contracts specified in tokenAddresses, else the campaign will fail to provide rewards. ----------------------------------------------------------------------------------------------------------------_

Parameters

NameTypeDescription
lstruct Erc20RewardMinterFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
campaignTransferRewardsDatabytesThe ABI-encoded data containing the following: - tokenAddresses: An address array containing the addresses of the ERC20 tokens encapsulated by the reward packet. - amountOfTokensPerPacket: A uint256 array specifying the amount for each corresponding token in tokenAddresses.

transferReward

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

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

_This function iteratively executes mint functions for all respective amounts of ERC20 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 mint method of the ERC20 token interface._

Parameters

NameTypeDescription
lstruct Erc20RewardMinterFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
toaddressThe address to receive the ERC20 assets encapsulated by the specified number of reward packets.
amountOfPacketsuint256The number of reward packets to account for.

On this page