Erc20RewardMinterFacet
This facet handles the configuration of reward packets (output) for staking campaigns and facilitates the minting of the assets encapsulated within these reward packets.
_This implementation is specifically designed for staking campaigns where the reward packet is constructed solely from ERC20 tokens, and where the campaign's reward asset handler holds the minter role or has minting privileges on these token contracts.
IMPORTANT:
- Extra care should be taken when specifying token amounts, especially when dealing with tokens of
varying decimal precision (see
setCampaignTransferRewards()
for more details). - 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
._
CampaignRewardConfigured
Emitted at setCampaignTransferRewards()
.
CampaignRewardPacketsTransferred
Emitted at transferReward()
.
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 ERC20 tokens should be included.
Requirements:
- The
tokenAddresses
andamountOfTokensPerPacket
arrays must have the same length. tokenAddresses
must contain valid, non-zero ERC20 token addresses.amountOfTokensPerPacket
must contain non-zero values.
Emits a {CampaignRewardConfigured}
event.
IMPORTANT:
-
In any case the values in
amountOfTokensPerPacket
should be parsed with each token's decimal precision (using wei values) at the API level. -
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
Name | Type | Description |
---|---|---|
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 ERC20 tokens encapsulated by the reward packet. - 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 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.
Emits a {CampaignRewardPacketsTransferred}
event._
Parameters
Name | Type | Description |
---|---|---|
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
from | address | The address from which the ERC20 assets encapsulated by the specified number of rewards packets to be "transferred". |
to | address | The address to receive the ERC20 assets encapsulated by the specified number of reward packets. |
amountOfPackets | uint256 | The number of reward packets to account for. |