Staking Protocolskeletons

CampaignCreationSkeleton

This facet is a core component of a staking platform (Staking Diamond), providing functionality to create staking campaigns with configurable setter functions for campaign parameters. The creation process includes both mandatory and optional configuration steps, allowing flexibility while enforcing essential requirements.

The registered setter functions must be defined in contracts that are added as facets to the staking diamond. These setter functions are categorized as required or optional and are executed during the campaign creation process based on the input provided. The execution order and data structure are critical for successfully setting up and creating campaigns.

OnlyAdminCanInitialize

error OnlyAdminCanInitialize(address nonAdminAccount)

Thrown when a non-admin account attempts to call restricted initialization functions.

AlreadyInitialized

error AlreadyInitialized()

Thrown when attempting to re-initialize.

NoRequiredSelectorsSpecifiedAtInitialize

error NoRequiredSelectorsSpecifiedAtInitialize()

Thrown when no required selectors are specified during initialization.

RequiredSelectorNotDiamondRegistered

error RequiredSelectorNotDiamondRegistered(bytes4 invalidSelector)

Thrown when a selector specified as required during initialization is not registered in the diamond.

OptionalSelectorNotDiamondRegistered

error OptionalSelectorNotDiamondRegistered(bytes4 invalidSelector)

Thrown when a selector specified as optional during initialization is not registered in the diamond.

InvalidCampaignCreationInput

error InvalidCampaignCreationInput(uint256 requiredSelectorsToExecuteLength, uint256 optionalSelectorsToExecuteLength, uint256 dataToExecuteLength)

Thrown when the number of required and optional selectors does not match the provided calldata.

RequiredSetterExecutionFailed

error RequiredSetterExecutionFailed(uint256 campaignId, bytes4 setterFunctionSelector, bytes inputData, bytes returnData)

Thrown when a required setter function execution fails during a campaign's creation process.

OptionalSetterExecutionFailed

error OptionalSetterExecutionFailed(uint256 campaignId, bytes4 setterFunctionSelector, bytes inputData, bytes returnData)

Thrown when a supported optional setter function execution fails during a campaign's creation process.

UnsupportedOptionalSelector

error UnsupportedOptionalSelector(bytes4 unsupportedSelector)

Thrown when an selector specified as optional is not supported for the campaign creation process.

CampaignCreationSkeletonInitialized

event CampaignCreationSkeletonInitialized(bytes4[] requiredSetterFunctionSelectors, bytes4[] optionalSetterFunctionSelectors)

Emitted at initCampaignCreation().

StakingCampaignCreated

event StakingCampaignCreated(uint256 campaignId, address creator, bytes4[] withOptionalSetterFunctionSelectors)

Emitted at createCampaign().

CampaignAssetManagersDeployed

event CampaignAssetManagersDeployed(uint256 campaignId, address inputAssetKeeper, address rewardAssetHandler)

Emitted at createCampaign().

initCampaignCreation

function initCampaignCreation(bytes initCampaignCreationData) external

Initializes the CampaignCreationStorage by registering the required and optional setter functions.

_The selectors of the targeted setter functions must belong to the facets added to the diamond. Setter functions corresponding to required selectors are executed mandatorily when a campaign is created. In contrast, setter functions corresponding to optional selectors are executed only if the creator of the campaign chooses to do so (see createCampaign()).

This function can only be called by the Admin (see AccessControlStakingFacet.sol).

Emits a {CampaignCreationSkeletonInitialized} event._

Parameters

NameTypeDescription
initCampaignCreationDatabytesThe ABI-encoded data containing the following: - requiredSelectors An array of mandatory setter function selectors (bytes4). - optionalSelectors An array of optional setter function selectors (bytes4).

createCampaign

function createCampaign(bytes campaignCreationData) external

Creates a new staking campaign by deploying a dedicated CampaignAssetManager for the campaign's input and another for its output. It then executes required setter functions, as well as any optional setter functions specified by the provided optional selectors. The ID assigned to the newly created campaign is calculated by incrementing the totalCampaigns counter defined in the general storage.

_The required and optional setter functions are registered in the storage via the initCampaignCreation() and are identified by their function selectors.

The dataToExecute array is divided into two parts:

Users must meet eligibility criteria to create campaigns (see creatorEligibility facets).

Emits a CampaignAssetManagersDeployed and {StakingCampaignCreated} event._

Parameters

NameTypeDescription
campaignCreationDatabytesThe ABI-encoded data containing the following: - optionalSelectorsToExecute An array of optional setter function selectors (bytes4) to be executed. - dataToExecute An array with the ABI-encoded input data for the respective required and optional setter functions.