Fraction ProtocolgenericFacetsfundingPacketFacet

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

error AlreadyInitialized()

Thrown when attempting to re-initialize.

InvalidSetAndCheckSelectorForFundingPacketsMixer

error InvalidSetAndCheckSelectorForFundingPacketsMixer(bytes4 invalidSelector)

Thrown at initializer when the setAndCheck selector specified is invalid.

InvalidTransferSelectorForFundingPacketsMixer

error InvalidTransferSelectorForFundingPacketsMixer(bytes4 invalidSelector)

Thrown at initializer when the transfer selector specified is invalid.

InvalidFundingPacketsMixerInitDataLengths

error InvalidFundingPacketsMixerInitDataLengths(uint256 selectorsLength, uint256 supportedAssetTypeCodesLength)

Thrown at initializer when the lengths of selectors and fundingPacketsAssetTypeCodes do not match.

CampaignNotOnCreationStateForSetting

error CampaignNotOnCreationStateForSetting(uint256 campaignId)

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

InvalidFundingPacketsMixerSetAndCheckDataLengths

error InvalidFundingPacketsMixerSetAndCheckDataLengths(uint256 fundingPacketsDataLength, uint256 fundingAssetTypeCodesLength)

Thrown at setAndCheck when the lengths of fundingPacketsData and fundingAssetTypeCodes arrays do not match.

UnsupportedFundingPacketAssetType

error UnsupportedFundingPacketAssetType(uint256 unsupportedAssetTypeCode)

Thrown at setAndCheck when an unsupported asset type code is specified as funding packets for a campaign.

STORAGE_SLOT

bytes32 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.

struct FunctionSelectors {
  bytes4 setAndCheckSelector;
  bytes4 transferSelector;
}

CampaignFundingAssetInfo

Struct containing the local codes for the asset types supported within funding packets of a staking campaign.

struct CampaignFundingAssetInfo {
  uint256[] activeFundingPacketsAssetTypeCodes;
}

Layout

Struct for managing information related to the FundingPacket Mixer and campaigns configuration.

struct Layout {
  bool isInitialized;
  mapping(uint256 => bool) isFundingAssetTypeSupported;
  mapping(uint256 => bytes4) setAndCheckSelectorForAssetType;
  mapping(uint256 => bytes4) transferSelectorForAssetType;
  mapping(uint256 => struct FundingPacketMixerStorage.CampaignFundingAssetInfo) fundingTypesForCampaign;
}

layout

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

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

initFundingPacketFacet

function initFundingPacketFacet(struct FundingPacketMixerStorage.Layout l, bytes initFundingPacketData) internal returns (uint256[])

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 and fundingAssetTypeCodes 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 the selectors array. ----------------------------------------------------------------------------------------------------------------_

Parameters

NameTypeDescription
lstruct FundingPacketMixerStorage.LayoutA reference to the Layout struct in storage.
initFundingPacketDatabytesThe 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

function setAndCheckFundingPacket(struct FundingPacketMixerStorage.Layout l, bytes postFractionFundingPacketData) internal returns (uint256, uint256[])

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 and fundingAssetTypeCodes 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 (see initFundingPacketFacet()).

  • The i-th member of the fundingAssetTypeCodes array should correspond to the i-th member of the fundingPacketsData array. ----------------------------------------------------------------------------------------------------------------_

Parameters

NameTypeDescription
lstruct FundingPacketMixerStorage.Layout
postFractionFundingPacketDatabytesThe 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

function transferFundingPackets(struct FundingPacketMixerStorage.Layout l, uint256 campaignId, address from, address to, uint256 amountOfPackets) internal

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

NameTypeDescription
lstruct FundingPacketMixerStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
fromaddressThe address from which the assets encapsulated by the specified number of funding packets to be transferred.
toaddressThe address to receive the assets encapsulated by the specified number of funding packets.
amountOfPacketsuint256The number of funding packets to account for.

isSetAndCheckSelectorForFundingPacketsMixerSupported

function isSetAndCheckSelectorForFundingPacketsMixerSupported(bytes4 selector) internal pure returns (bool)

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

NameTypeDescription
selectorbytes4The function selector to check.

Return Values

NameTypeDescription
[0]boolbool True if selector is supported, false otherwise.

isTransferSelectorForFundingPacketsMixerSupported

function isTransferSelectorForFundingPacketsMixerSupported(bytes4 selector) internal pure returns (bool)

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

NameTypeDescription
selectorbytes4The function selector to check.

Return Values

NameTypeDescription
[0]boolbool True if selector is supported, false otherwise.