Staking ProtocolvirtualAmountMultiplierintervalVirtualAmountMultiplier

IntervalVirtualAmountMultiplierFacetStorage

This library manages the storage and logic for the application of amount multipliers (used for scaling rewards) within staking campaigns according to an interval-based schema.

_Example of an interval-based schema configuration: If amountsStaked = [100, 200, 300] and amountStakedMultipliers = [1.1, 1.2, 1.3]:

  • A position with less than 100 staked packets will receive an amount multiplier of 1 (no multiplier).
  • A position with staked packets between 100 and 199 will receive an amount multiplier of 1.1.
  • A position with staked packets between 200 and 299 will receive an amount multiplier of 1.2.
  • A position with staked packets 300 or more will receive an amount multiplier of 1.3.

IMPORTANT:

  • Multipliers should be scaled by 1e18, allowing for calculations with up to 18 decimal precision. -amountsStaked and amountStakedMultipliers must be in strictly increasing order._

CampaignNotOnCreationStateForSetting

error CampaignNotOnCreationStateForSetting(uint256 campaignId)

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

NoAmountMultiplierDataProvided

error NoAmountMultiplierDataProvided(uint256 campaignId)

Thrown at setter when no data provided for either amountsStaked or amountStakedMultipliers

InvalidAmountMultiplierDataLengths

error InvalidAmountMultiplierDataLengths(uint256 campaignId, uint256 amountsStakedLength, uint256 amountStakedMultipliersLength)

Thrown at setter when the lengths of amountsStaked and amountStakedMultipliers do not match.

InvalidZeroFirstAmountMultiplierData

error InvalidZeroFirstAmountMultiplierData(uint256 campaignId, uint256 amount, uint256 amountMultiplier)

Thrown at setter when the first element of amountsStaked or amountStakedMultipliers is zero.

InvalidAmountMultiplierDataOrder

error InvalidAmountMultiplierDataOrder(uint256 campaignId)

Thrown at setter when the amountsStaked or amountStakedMultipliers are not in strictly increasing order.

STORAGE_SLOT

bytes32 STORAGE_SLOT

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

DIVIDER

uint256 DIVIDER

Used to normalize values (e.g., multipliers) for calculations with up to 18 decimal precision.

Layout

Struct for managing information related to amount-wise multipliers.

struct Layout {
  mapping(uint256 => struct IntervalVirtualAmountMultiplierFacetStorage.CampaignInfo) campaignInfoLocal;
  mapping(uint256 => uint256) amountMultiplierForNftId;
}

CampaignInfo

Struct containing the configuration information for amount-wise multipliers in a staking campaign.

struct CampaignInfo {
  uint256[] amountsStaked;
  uint256[] amountStakedMultipliers;
}

layout

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

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

setCampaignVirtualAmountMultipliers

function setCampaignVirtualAmountMultipliers(struct IntervalVirtualAmountMultiplierFacetStorage.Layout l, uint256 campaignId, bytes campaignVirtualAmountMultipliersData) internal returns (uint256[], uint256[])

Setter function for configuring amount multipliers for the specified staking campaign.

_Setter functions are executed during the creation process of campaigns (see CampaignCreationSkeleton.sol). This function allows for the configuration of thresholds and their respective multipliers for staked amounts.

The lengths of the amountsStaked and amountStakedMultipliers arrays must be equal. Each threshold defined in amountsStaked should correspond to a multiplier in amountStakedMultipliers._

Parameters

NameTypeDescription
lstruct IntervalVirtualAmountMultiplierFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
campaignVirtualAmountMultipliersDatabytesThe ABI-encoded data containing the following: - amountsStaked: A uint256 array of input packet amounts defining amount thresholds for amount-based multipliers. - amountStakedMultipliers: A uint256 array of respective multiplier values for each threshold (scaled by 1e18).

applyVirtualAmountMultiplier

function applyVirtualAmountMultiplier(struct IntervalVirtualAmountMultiplierFacetStorage.Layout l, uint256 campaignId, uint256 nftId, uint256 totalAmountStaked) internal returns (uint256)

Calculates and applies the respective amount multiplier to the specified position based on the campaign's configuration and the position's total staked amount of input packets.

This function returns the virtual balance of the specified position, calculated as the position's actual raw balance multiplied by the applicable amount multiplier.

Parameters

NameTypeDescription
lstruct IntervalVirtualAmountMultiplierFacetStorage.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.
totalAmountStakeduint256The actual raw balance (in staked input packets) of the position.

Return Values

NameTypeDescription
[0]uint256The calculated virtual balance of the position.