Fraction ProtocolgenericFacetsstateFacet

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 from 0.
  • 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 (see CreateFractionsSkeleton.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

error UnauthorizedInitialization(address account)

Thrown when trying to initialize from non admin account.

StateSystemInitialized

event StateSystemInitialized()

StateChanged

event StateChanged(uint256 campaignId, uint256 fromState, uint256 toState)

initStateFacet

function initStateFacet(bytes initStateData) external

Initializes the StateFacetStorage by setting the schema for state transitions and their respective hooks.

Parameters

NameTypeDescription
initStateDatabytes

changeState

function changeState(uint256 campaignId, uint256 fromState, uint256 toState) external

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

NameTypeDescription
campaignIduint256The unique identifier of the targeted campaign.
fromStateuint256The state to depart from (should be current state).
toStateuint256The destination state (the new state to settle).

getStateOfId

function getStateOfId(uint256 campaignId) external view returns (uint256)

Retrieves the current state of the specified campaign.

Parameters

NameTypeDescription
campaignIduint256The unique identifier of the targeted campaign.

Return Values

NameTypeDescription
[0]uint256The current state of campaignId.

On this page