StateFacet
This facet is a core component of any tmi-fractions platform. It acts as a programmable state machine, enabling state transitions within campaigns and triggering specific functions (hooks) based on a defined schema.
_The campaign states configuration follows a schema where each state has an associated set of states representing
the allowed state transitions. Platform facet functions can be designated as either beforeHooks
or afterHooks
via
their respective function selectors. Each state can have multiple beforeHooks
and/or afterHooks
assigned.
A state's beforeHooks
are triggered sequentially when the state is reached from another one. A state's afterHooks
are triggered sequentially when there is a departure from this state to another.
IMPORTANT:
- States are represented internally as
uint256
starting from0
. - State
0
is the default state (i.e., campaign does not exist) for any campaign within the platform. - State
1
is always exclusively reached after the createFractions call (seeCreateFractionsSkeleton.sol
). - The remaining states (however many they are) are not predefined and can be configured according to the platform's needs.
EXAMPLE:
- If campaigns do not need approval/validation to progress to purchase phase, then purchaseState should be assigned as the state
1
. - If campaigns need approval/validation to progress to purchase phase, then purchaseState can be assigned as the state
2
. - The remaining states can be assigned according to the platform's use case.
- This flexible approach provides limitless opportunities for state handling._
UnauthorizedInitialization
Thrown when trying to initialize from non admin account.
StateSystemInitialized
StateChanged
initStateFacet
Initializes the StateFacetStorage
by setting the schema for state transitions and their respective hooks.
Parameters
Name | Type | Description |
---|---|---|
initStateData | bytes |
changeState
Changes the specified campaign's state from fromState
to toState
.
Can only be called internally by the diamond proxy itself (i.e., from other facets).
The campaign's current state must be fromState
, and toState
must be a valid transition from the current state;
otherwise, the function reverts.
Parameters
Name | Type | Description |
---|---|---|
campaignId | uint256 | The unique identifier of the targeted campaign. |
fromState | uint256 | The state to depart from (should be current state). |
toState | uint256 | The destination state (the new state to settle). |
getStateOfId
Retrieves the current state of the specified campaign.
Parameters
Name | Type | Description |
---|---|---|
campaignId | uint256 | The unique identifier of the targeted campaign. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | The current state of campaignId . |