Staking ProtocolcampaignAmountstwoBorderAmountFacet

TwoBorderAmountFacetStorage

TwoBorderAmountFacetStorage

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 configure minimum and maximum limits on the number of input packets supported by positions within any campaign.

CampaignNotOnCreationStateForSetting

error CampaignNotOnCreationStateForSetting(uint256 campaignId)

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

PositionsMaxAmountOfPacketsCannotBeZero

error PositionsMaxAmountOfPacketsCannotBeZero(uint256 campaignId)

Thrown when attempting to set a campaign's positions' max amount of staked packets to zero.

PositionsMaxAmountLessThanMinAmountOfPackets

error PositionsMaxAmountLessThanMinAmountOfPackets(uint256 campaignId, uint256 minAmountOfPackets, uint256 maxAmountOfPackets)

Thrown when setting a campaign's positions' max amount of packets less than the minimum required.

PacketsToStakeCannotBeZero

error PacketsToStakeCannotBeZero()

Thrown when the specified amount of input packets is zero.

PacketsToStakeNotWithinAcceptedRange

error PacketsToStakeNotWithinAcceptedRange(uint256 campaignId, uint256 requiredMinAmount, uint256 allowedMaxAmount, uint256 amountOfPacketsToStake)

Thrown at stake when the amount of packets is outside the accepted range for a campaign's positions.

PositionExceedsMaxAmountOfPackets

error PositionExceedsMaxAmountOfPackets(uint256 campaignId, uint256 nftId, uint256 allowedMaxAmount, uint256 amountOfPacketsStaked, uint256 amountOfPacketsToStake)

Thrown when the resulting packets after staking exceeds the maximum set for a campaign's positions.

PacketsToUnstakeCannotBeZero

error PacketsToUnstakeCannotBeZero()

Thrown when attempting to unstake zero packets.

CannotPartiallyUnstakeMoreOrEqualToStaked

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

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

RemainingPacketsBelowMinRequired

error RemainingPacketsBelowMinRequired(uint256 campaignId, uint256 nftId, uint256 remainingPackets, uint256 minAmountOfPackets)

Thrown when the remaining packets after partially unstaking are less than the required minimum.

STORAGE_SLOT

bytes32 STORAGE_SLOT

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

Layout

Struct for managing amount-based configuration details for staking campaigns.

struct Layout {
  mapping(uint256 => struct TwoBorderAmountFacetStorage.CampaignAmounts) campaignAmounts;
}

CampaignAmounts

Struct containing the amount-based configuration for a staking campaign.

struct CampaignAmounts {
  uint256 minAmountOfPackets;
  uint256 maxAmountOfPackets;
}

layout

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

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

setCampaignAmountsData

function setCampaignAmountsData(struct TwoBorderAmountFacetStorage.Layout l, uint256 campaignId, bytes campaignAmountsData) internal returns (uint256, 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 the minimum and maximum limits on the number of input packets that a campaign's position can support.

IMPORTANT:

  • maxAmountOfPackets must be strictly greater than 0.
  • minAmountOfPackets must be less than or equal to maxAmountOfPackets._

Parameters

NameTypeDescription
lstruct TwoBorderAmountFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
campaignAmountsDatabytesThe ABI-encoded data containing the following: - minAmountOfPackets: The minimum number of input packets required to create and maintain a position within the campaign. - maxAmountOfPackets: The maximum number of input packets that a position can support within the campaign.

checkInputPackets

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

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

_Reverts if amountOfPackets is 0 or outside the configured limits for the campaign (see setCampaignAmountsData()).

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

Parameters

NameTypeDescription
lstruct TwoBorderAmountFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
nftIduint256The unique identifier of the NFT associated with the position.
amountOfPacketsuint256The number of input packets to check.

checkUnstakePackets

function checkUnstakePackets(struct TwoBorderAmountFacetStorage.Layout l, uint256 campaignId, uint256 nftId, uint256 amountOfPacketsToUnstake, 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, if amountOfPackets is greater than or equal to the position's total staked packets, or if the position's remaining staked packets would fall below the campaign's configured minAmountOfPackets (see setCampaignAmountsData()), which is required to maintain active positions._

Parameters

NameTypeDescription
lstruct TwoBorderAmountFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
nftIduint256The unique identifier of the NFT associated with the position.
amountOfPacketsToUnstakeuint256The number of input packets to check.
isPartialUnstakeboolA flag indicating whether the unstake is partial (true) or full (false).