Erc20InputFacetStorage
This library manages the storage and logic for handling the configuration of input packets for staking campaigns and facilitates their transfer.
_This implementation is designed for use in staking campaigns where the input packet is constructed solely from ERC20 tokens.
IMPORTANT:
- Extra care should be taken when specifying token amounts, especially when dealing with tokens of
varying decimal precision (see
setCampaignTransferInput()
for more details). - An input packet can encapsulate one (e.g., tokenA) or more (e.g., tokenA, tokenB, ..., tokenX) ERC20 tokens._
CampaignNotOnCreationStateForSetting
Thrown when a targeted campaign is not "On Creation" state, which is required at configurations.
NoInputPacketDataProvided
Thrown at setter when no data provided for either tokenAddresses
or amountOfTokensPerPacket
.
InvalidInputPacketDataLengths
Thrown at setter when the lengths of tokenAddresses
and amountOfTokensPerPacket
do not match.
InvalidZeroInputPacketAddressData
Thrown at setter when an element of tokenAddresses
is the zero address.
InvalidZeroInputPacketAmountData
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' input packets.
InputPacket
Struct containing the configuration information for an input packet.
layout
Retrieves a reference to the Layout struct stored at the slot specified by STORAGE_SLOT
unique identifier.
setCampaignTransferInput
Setter function for configuring the input packet for the specified staking campaign.
_Setter functions are executed during the creation process of campaigns (see CampaignCreationSkeleton.sol
).
This setter function configures the input 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.
IMPORTANT:
-
If all ERC20 tokens in
tokenAddresses
have the same decimal places, there are two configuration options.-
Parse the values in
amountOfTokensPerPacket
with the appropriate common number of decimal digits (using wei values). In this case, input packet amounts should be specified in whole units at the API level forstake()
,restake()
,partialUnstake()
, andfullyUnstake()
(seeStakingSkeleton.sol
). -
Specify values in
amountOfTokensPerPacket
in whole units, thus, input packet amounts should be parsed with the appropriate common number of decimal digits (using wei values) at the API level instake()
,restake()
,partialUnstake()
, andfullyUnstake()
(seeStakingSkeleton.sol
).
-
-
If any ERC20 token in
tokenAddresses
has a different decimal precision than others, only one option is valid:Parse the values in
amountOfTokensPerPacket
with each token's decimal precision (using wei values), thus, input packet amounts should be specified in whole units at the API level forstake()
,restake()
,partialUnstake()
, andfullyUnstake()
(seeStakingSkeleton.sol
). ----------------------------------------------------------------------------------------------------------------_
Parameters
Name | Type | Description |
---|---|---|
l | struct Erc20InputFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
campaignTransferInputData | bytes | The ABI-encoded data containing the following: - tokenAddresses : An address array containing the addresses of the ERC20 tokens encapsulated by the input packet. - amountOfTokensPerPacket : A uint256 array specifying the amount for each corresponding token in tokenAddresses . |
transferInput
Transfers the specified amount of a given campaign's input packets from the from
address
to the to
address.
_This function iteratively executes transfers for all respective amounts of ERC20 tokens defined
in the campaign's input packet (see setCampaignTransferInput()
) in a single transaction.
The amounts to be transferred are calculated as
amountOfTokensPerPacket[i] * amountOfPackets
for each token in the input packet, where i
is the index of the token in the tokenAddresses
array. The transfer is performed using
the safeTransferFrom
method of the ERC20 token interface._
Parameters
Name | Type | Description |
---|---|---|
l | struct Erc20InputFacetStorage.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 ERC20 assets encapsulated by the specified number of input packets to be transferred. |
to | address | The address to receive the ERC20 assets encapsulated by the specified number of input packets. |
amountOfPackets | uint256 | The number of input packets to account for. |