FundingPacketMixerStorage
This library implementation ensembles Funding Packets Explicit Facets enabling the configuration of campaigns' funding packets that can encapsulate diverse asset types (e.g., ERC20, ERC1155 etc.), and facilitate the transfer of these funding packets.
We do not use the custom:storage-location
annotation because the Layout struct is defined in a library,
which, as of now, does not support automated storage layout validation.
However, the implementation adheres to the ERC-7201 structure in spirit by ensuring unique and
collision-free storage slots using the ERC-7201 formula.
AlreadyInitialized
Thrown when attempting to re-initialize.
InvalidSetAndCheckSelectorForFundingPacketsMixer
Thrown at initializer when the setAndCheck selector specified is invalid.
InvalidTransferSelectorForFundingPacketsMixer
Thrown at initializer when the transfer selector specified is invalid.
InvalidFundingPacketsMixerInitDataLengths
Thrown at initializer when the lengths of selectors
and fundingPacketsAssetTypeCodes
do not match.
CampaignNotOnCreationStateForSetting
Thrown when a targeted campaign is not "On Creation" state, which is required at configurations.
InvalidFundingPacketsMixerSetAndCheckDataLengths
Thrown at setAndCheck when the lengths of fundingPacketsData
and fundingAssetTypeCodes
arrays do not match.
UnsupportedFundingPacketAssetType
Thrown at setAndCheck when an unsupported asset type code is specified as funding packets for a campaign.
STORAGE_SLOT
Unique identifier for the storage slot where the Layout struct is stored. Derived from the ERC7201 formula.
FunctionSelectors
Struct containing selectors of set and check & transfer functions implemented in a Funding Packets Explicit Facet.
CampaignFundingAssetInfo
Struct containing the local codes for the asset types supported within funding packets of a staking campaign.
Layout
Struct for managing information related to the FundingPacket Mixer and campaigns configuration.
layout
Retrieves a reference to the Layout struct stored at the slot specified by STORAGE_SLOT
unique identifier.
initFundingPacketFacet
Initializes the FundingPacketMixerStorage
by registering the selectors for the setAndCheck and
transferFundingPackets functions of the supported FundingPackets Explicit facets, along with code schema for
representing the ERC types handled by these Explicit facets.
_The selectors provided must belong to the FundingPackets Explicit facets that will be used for constructing funding packets of campaigns and for transferring assets encapsulated within a campaign's funding packet.
Requirements:
- The
selectors
andfundingAssetTypeCodes
arrays must have the same length.
IMPORTANT:
-
The code schema for supported ERCs in campaigns' funding packets helps identify the asset type that each registered Funding Packets Explicit 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 of the ERCs (e.g., 20 for ERC20, 1155 for ERC1155 etc.) as codes for clarity and consistency.
-
The i-th member of the
fundingAssetTypeCodes
array should correspond to the i-th member of theselectors
array. ----------------------------------------------------------------------------------------------------------------_
Parameters
Name | Type | Description |
---|---|---|
l | struct FundingPacketMixerStorage.Layout | A reference to the Layout struct in storage. |
initFundingPacketData | bytes | The ABI encoded data containing the following: - selectors : An array of FunctionSelectors structs, each with the setAndCheck and transferFundingPackets function selectors of the supported FundingPackets Explicit facets. - fundingAssetTypeCodes : The code schema that identifies the ERC (asset type) each supported FundingPackets Explicit facet hanldles. |
setAndCheckFundingPacket
Configures and validates the funding packet of a campaign.
_This Set and Check function configures the funding packet for a campaign, where any of the supported asset types can be included. For instance, if ERC20 and ERC1155 FundingPackets 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 funding packet is at the discreation of the campaign creator, as
any possible combination of the supported FundingPackets Explicit facets can be employed.
These explicit facets must be already registered via initFundingPacketFacet()
.
Set and Check functions are executed during the creation process of campaigns (see CreateFractionsSkeleton.sol
).
Requirements:
- The
fundingPacketsData
andfundingAssetTypeCodes
arrays must have the same length.
IMPORTANT:
-
The asset type codes specified in
fundingAssetTypeCodes
should be valid, meaning that they should already be registered in the FundingPacket Mixer storage (seeinitFundingPacketFacet()
). -
The i-th member of the
fundingAssetTypeCodes
array should correspond to the i-th member of thefundingPacketsData
array. ----------------------------------------------------------------------------------------------------------------_
Parameters
Name | Type | Description |
---|---|---|
l | struct FundingPacketMixerStorage.Layout | |
postFractionFundingPacketData | bytes | The ABI-encoded settings data containing the following: - fundingPacketsData : An bytes array with the ABI encoded data to be consumed as input by the Set and Check functions of the targeted Funding Packets Explicit facets. - fundingAssetTypeCodes : A uint256 array with the respective configured codes indicating the targeted Funding Packets Explicit facets to be used. |
transferFundingPackets
Transfers the specified amount of a given campaign's funding packets from the from
address
to the to
address.
This function iteratively executes the respective transferFundingPackets
functions of all
Funding Packets Explicit facets associated with the funding packet.
Parameters
Name | Type | Description |
---|---|---|
l | struct FundingPacketMixerStorage.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 assets encapsulated by the specified number of funding packets to be transferred. |
to | address | The address to receive the assets encapsulated by the specified number of funding packets. |
amountOfPackets | uint256 | The number of funding packets to account for. |
isSetAndCheckSelectorForFundingPacketsMixerSupported
Determines whether a given function selector is supported by this Mixer as a setAndCheck function selector.
_This function checks if the provided selector
matches one of the predefined supported selectors.
The supported selectors are stored in a local fixed-size memory array and compared against the funding packet.
IMPORTANT:
- The supported setAndCheck function selectors correspond to the setAndCheck functions of the Explicit facets associated with this Mixer._
Parameters
Name | Type | Description |
---|---|---|
selector | bytes4 | The function selector to check. |
Return Values
Name | Type | Description |
---|---|---|
[0] | bool | bool True if selector is supported, false otherwise. |
isTransferSelectorForFundingPacketsMixerSupported
Determines whether a given function selector is supported by this Mixer as a transfer function selector.
_This function checks if the provided selector
matches one of the predefined supported selectors.
The supported selectors are stored in a local fixed-size memory array and compared against the funding packet.
IMPORTANT:
- The supported transfer function selectors correspond to the transfer functions of the Explicit facets associated with this Mixer._
Parameters
Name | Type | Description |
---|---|---|
selector | bytes4 | The function selector to check. |
Return Values
Name | Type | Description |
---|---|---|
[0] | bool | bool True if selector is supported, false otherwise. |