Staking ProtocolcampaignAmountshardcapAmountFacet

HardcapAmountFacetStorage

HardcapAmountFacetStorage

This library manages the storage and logic for applying amount-based packet configurations for staking campaigns and handles amount-based checks that should be performed during staking and unstaking operations.

This implementation is designed to manage and configure hardcaps on the total number of input packets that can be allocated to each campaign.

CampaignNotOnCreationStateForSetting

error CampaignNotOnCreationStateForSetting(uint256 campaignId)

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

PacketsToStakeCannotBeZero

error PacketsToStakeCannotBeZero()

Thrown when the specified amount of input packets is zero.

AmountStakedExceedsHardcap

error AmountStakedExceedsHardcap(uint256 campaignId, uint256 inputPacketAmount, uint256 resultingTotalPacketAmount, uint256 hardcap)

Thrown when the resulting total amount of packets staked in the campaign exceeds the campaign's hardcap.

PacketsToUnstakeCannotBeZero

error PacketsToUnstakeCannotBeZero()

Thrown when attempting to unstake zero packets.

CannotPartiallyUnstakeMoreOrEqualToStaked

error CannotPartiallyUnstakeMoreOrEqualToStaked(uint256 nftId, uint256 packetsToUnstake, uint256 packetsStaked)

Thrown when attempting to partially unstake more or equal packets than/to currently staked.

STORAGE_SLOT

bytes32 STORAGE_SLOT

Unique identifier for the storage slot where the Layout struct is stored.

Layout

Struct for managing information related to campaigns' hardcaps.

struct Layout {
  mapping(uint256 => uint256) hardcapForCampaign;
}

layout

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

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

setCampaignAmountsData

function setCampaignAmountsData(struct HardcapAmountFacetStorage.Layout l, uint256 campaignId, bytes campaignAmountsData) internal returns (uint256)

Setter function for configuring amount-based packet constraints for the specified staking campaign.

_Setter functions are executed during the creation process of campaigns (see CampaignCreationSkeleton.sol).

This function allows for setting an upper limit (hardcap) on the total number of input packets that can be staked within a campaign.

IMPORTANT: If packetsHardcap == 0, then no upper limit is enforced on the specified campaign._

Parameters

NameTypeDescription
lstruct HardcapAmountFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
campaignAmountsDatabytesThe ABI-encoded data containing the following: - packetsHardcap: The maximum number of input packets that can be allocated to the campaign.

checkInputPackets

function checkInputPackets(struct HardcapAmountFacetStorage.Layout l, uint256 campaignId, uint256, uint256 amountOfPackets) internal view

Checks whether the specified amount of packets can be allocated within a given campaign.

_Reverts if amountOfPackets is 0 or if it would cause the campaign's total staked packets to exceed the configured hardcap.

IMPORTANT: If nftId == 0, the check is performed for a new stake operation; otherwise, it is performed for a restake operation.

Note: The position (i.e., nftId) is not considered in this implementation as the hardcap only applies to the campaign's total staked packets. Therefore, the check for both stake and restake is the same._

Parameters

NameTypeDescription
lstruct HardcapAmountFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
uint256
amountOfPacketsuint256The number of input packets to check.

checkUnstakePackets

function checkUnstakePackets(struct HardcapAmountFacetStorage.Layout, uint256, uint256 nftId, uint256 amountOfPackets, bool isPartialUnstake) internal view

Checks whether the specified amount of packets can be withdrawn from a given campaign's position.

Reverts if amountOfPackets is 0. For partial unstaking, it also reverts if amountOfPackets is greater than or equal to the position's total staked packets.

Parameters

NameTypeDescription
struct HardcapAmountFacetStorage.Layout
uint256
nftIduint256The unique identifier of the NFT associated with the position.
amountOfPacketsuint256The number of input packets to check.
isPartialUnstakeboolA flag indicating whether the unstake is partial (true) or full (false).