FundingErc20PacketsFacetStorage
This library manages the storage and logic for handling the configuration of funding packets for campaigns and facilitates their transfer.
_This implementation is designed for use in campaigns where the funding 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.
- A funding packet can encapsulate one (e.g., tokenA) or more (e.g., tokenA, tokenB, ..., tokenX) ERC20 tokens.
NOTE:
- 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._
NoInitFundingPacketDataProvided
Thrown at initializer when no data provided for tokenAddresses
.
NoFundingPacketDataProvided
Thrown at setter when no data provided for either tokenAddresses
or amountOfTokensPerPacket
.
InvalidFundingPacketDataLengths
Thrown at setter when the lengths of tokenAddresses
and amountOfTokensPerPacket
do not match.
InvalidZeroFundingPacketAddressData
Thrown at setter when an element of tokenAddresses
is the zero address.
InvalidZeroFundingPacketAmountData
Thrown at setter when an element of amountOfTokensPerPacket
is zero.
AlreadyImportedTokenAddress
Thrown when trying to import a funding token address that has already been imported.
TokenAddressNotAllowed
Thrown when trying to import a funding token address that is not allowed.
InvalidTokenAddress
Thrown when trying to import an incorrect funding token address. (ex. not an ERC20 token or wrong address)
AlreadyAcceptedTokenAddress
Thrown when trying to accept a funding token address that has already been accepted.
TokenAddressWasNotAccepted
Thrown when trying to remove a funding token address that was not accepted.
STORAGE_SLOT
Unique identifier for the storage slot where the Layout struct is stored. Derived from the ERC7201 formula.
Layout
Struct for managing information related to campaigns' funding packets.
FundingPacket
Struct containing the configuration information for an funding packet.
layout
Retrieves a reference to the Layout struct stored at the slot specified by STORAGE_SLOT
unique identifier.
initFundingErc20PacketFacet
Initializes the FundingErc20PacketsFacetStorage
by setting the approved ERC20 tokens.
If a token is already imported, AlreadyImportedTokenAddress
error is thrown.
These tokens serve as valid funding currencies within the platform.
Parameters
Name | Type | Description |
---|---|---|
l | struct FundingErc20PacketsFacetStorage.Layout | |
initFundingPacketData | bytes | The ABI-encoded data containing the following: approvedTokens : An array of ERC20 token addresses approved for inclusion in input packets. |
setAndCheckFundingPacket
Configures and validates the funding packet of a campaign.
_Set and Check functions are executed during the creation process of campaigns (see CreateFractionsSkeleton.sol
).
This function configures the funding packet for a campaign, where only ERC20 tokens should be included.
Requirements:
- The
tokenAddresses
andamountOfTokensPerPacket
arrays must have the same length. tokenAddresses
must contain approved ERC20 token addresses.amountOfTokensPerPacket
must contain non-zero values.
IMPORTANT:
-
If all ERC20 tokens in
tokenAddresses
have the same decimal places, two configuration options exist:-
Parse values in
amountOfTokensPerPacket
using the common decimal precision (wei values). In this case, funding packet amounts should be specified in whole units at the API level. This option is only viable when no Discount & no Interest mechanisms are featured in the campaign. -
Specify values in
amountOfTokensPerPacket
in whole units, thus, funding packet amounts should be parsed with the appropriate number of decimal digits at the API level (e.g., inBuybackSekelton.buyback()
etc.).
-
-
If any ERC20 token in
tokenAddresses
has a different decimal precision than others, only one option is valid:- Parse
amountOfTokensPerPacket
using each token’s specific decimal precision (wei values). Funding packet amounts must then be specified in whole units at the API level forpurchase()
, etc. As stated above, such a funding packet cannot be used in campaigns featuring Discount or Interest mechanisms. ----------------------------------------------------------------------------------------------------------------------------_
- Parse
Parameters
Name | Type | Description |
---|---|---|
l | struct FundingErc20PacketsFacetStorage.Layout | A reference to the Layout struct in storage. |
postFractionFundingPacketData | 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 . |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The ID of the campaign for which the funding packet is configured. |
[1] | address[] | address[] The tokenAddresses array. |
[2] | uint256[] | uint256[] The amountOfTokensPerPacket array. |
transferFundingPackets
Transfers the specified amount of a given campaign's funding packets from the from
address
to the to
address.
The amounts to be transferred are calculated as:
amountOfTokensPerPacket[i] * amountOfPackets
for each token in the funding 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 FundingErc20PacketsFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted campaign. |
from | address | The address from which the ERC20 assets encapsulated by the specified number of funding packets to be transferred. |
to | address | The address to receive the ERC20 assets encapsulated by the specified number of funding packets. |
amountOfPackets | uint256 | The number of funding packets to account for. |