Staking ProtocolsubInternalFacetsvirtualLockMultiplierintervalVirtualLockMultiplier

IntervalVirtualLockMultiplierFacetStorage

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

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

  • A position with lock duration less than 100 seconds will receive a lock multiplier of 1 (no multiplier).
  • A position with lock duration between 100 and 199 seconds will receive a lock multiplier of 1.1.
  • A position with lock duration between 200 and 299 seconds will receive a lock multiplier of 1.2.
  • A position with lock duration 300 seconds or more will receive a lock multiplier of 1.3.

IMPORTANT:

  • Multipliers should be scaled by 1e18, allowing for calculations with up to 18 decimal precision. -timeLockPeriods and timeLockMultipliers 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.

NoTimeLockMultiplierDataProvided

error NoTimeLockMultiplierDataProvided(uint256 campaignId)

Thrown at setter when no data provided for either timeLockPeriods or timeLockMultipliers.

InvalidTimeLockMultiplierDataLengths

error InvalidTimeLockMultiplierDataLengths(uint256 campaignId, uint256 timeLockPeriodsLength, uint256 timeLockMultipliersLength)

Thrown at setter when the lengths of timeLockPeriods and timeLockMultipliers do not match.

InvalidZeroFirstTimeLockMultiplierData

error InvalidZeroFirstTimeLockMultiplierData(uint256 campaignId, uint256 timeLockPeriod, uint256 timeLockMultiplier)

Thrown at setter when the first element of timeLockPeriods or timeLockMultipliers is zero.

InvalidTimeLockMultiplierDataOrder

error InvalidTimeLockMultiplierDataOrder(uint256 campaignId)

Thrown at setter when the timeLockPeriods or timeLockMultipliers 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 lock-wise multipliers.

struct Layout {
  mapping(uint256 => struct IntervalVirtualLockMultiplierFacetStorage.CampaignInfo) campaignInfoLocal;
  mapping(uint256 => uint256) lockMultiplierForNftId;
}

CampaignInfo

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

struct CampaignInfo {
  uint256[] timeLockPeriods;
  uint256[] timeLockMultipliers;
}

layout

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

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

setCampaignVirtualLockMultipliers

function setCampaignVirtualLockMultipliers(struct IntervalVirtualLockMultiplierFacetStorage.Layout l, uint256 campaignId, bytes campaignVirtualLockMultipliersData) internal returns (uint256[], uint256[])

Setter function for configuring lock 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 lock periods.

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

Parameters

NameTypeDescription
lstruct IntervalVirtualLockMultiplierFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
campaignVirtualLockMultipliersDatabytesThe ABI-encoded data containing the following: - timeLockPeriods: A uint256 array of time durations (in seconds) defining lock duration thresholds for lock-based multipliers. - timeLockMultipliers: A uint256 array of respective multiplier values for each threshold (scaled by 1e18).

applyVirtualLockMultiplier

function applyVirtualLockMultiplier(struct IntervalVirtualLockMultiplierFacetStorage.Layout l, uint256 campaignId, uint256 nftId) internal returns (uint256)

Applies the respective lock multiplier to the specified position based on the campaign's configuration and the position's lock period.

Lock multipliers are scaled by 1e18, allowing for 18 decimal precision.

Parameters

NameTypeDescription
lstruct IntervalVirtualLockMultiplierFacetStorage.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.

Return Values

NameTypeDescription
[0]uint256The value of the applied lock multiplier.

combineVirtualLockMultipliers

function combineVirtualLockMultipliers(struct IntervalVirtualLockMultiplierFacetStorage.Layout l, uint256 nftId, uint256 currentLockMultiplier, uint256 newLockMultiplier, uint256 packetsStaked, uint256 packetsRestaked) internal returns (uint256)

Applies to the specified position the calculated combined lock multiplier.

IMPORTANT: This adjustment occurs when a position's lock period hasn't elapsed and the position is increased via a restake operation. The combined lock multiplier for calculating rewards is accounted for the period between the position's current unlock timestamp and the restake's unlocktimestamp.

Parameters

NameTypeDescription
lstruct IntervalVirtualLockMultiplierFacetStorage.LayoutA reference to the Layout struct in storage.
nftIduint256The unique identifier of the NFT associated with the position.
currentLockMultiplieruint256The value of the lock multiplier currently applied to the position.
newLockMultiplieruint256The lock multiplier applicable for the restake's lock period.
packetsStakeduint256The total amount of staked input packets in the current position.
packetsRestakeduint256The amount of input packets to be allocated during the restake operation.

Return Values

NameTypeDescription
[0]uint256The calculated combined lock multiplier value.

calculateVirtualLockMultiplier

function calculateVirtualLockMultiplier(struct IntervalVirtualLockMultiplierFacetStorage.Layout l, uint256 campaignId, uint256 timeLockPeriod) internal view returns (uint256)

Calculates the lock multiplier based on the specified campaign's configuration and the provided lock duration.

Lock multipliers are scaled by 1e18, allowing for 18 decimal precision.

Parameters

NameTypeDescription
lstruct IntervalVirtualLockMultiplierFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted staking campaign.
timeLockPerioduint256The lock duration for which the multiplier will be calculated.

Return Values

NameTypeDescription
[0]uint256The calculated lock multiplier value.

getVirtualBalance

function getVirtualBalance(struct IntervalVirtualLockMultiplierFacetStorage.Layout l, uint256 nftId) internal view returns (uint256)

Calculates and retrieves the virtual balance of the specified position. The virtual balance is calculated as the position's actual raw balance (staked input packets) multiplied by the applicable amount and lock multiplier.

Parameters

NameTypeDescription
lstruct IntervalVirtualLockMultiplierFacetStorage.LayoutA reference to the Layout struct in storage.
nftIduint256The unique identifier of the NFT associated with the position.

Return Values

NameTypeDescription
[0]uint256The virtual balance of the position accounting for both any applicable amount and lock multipliers.

getVirtualBalanceForAmount

function getVirtualBalanceForAmount(struct IntervalVirtualLockMultiplierFacetStorage.Layout l, uint256 nftId, uint256 amountOfPackets) internal view returns (uint256)

Retrieves the virtual amount of packets based on the specified amount of packets and the position's applicable lock multiplier (virtualAmount = amountOfPackets * lockMultiplierApplied).

This function only accounts for any applicable lock multiplier.

Parameters

NameTypeDescription
lstruct IntervalVirtualLockMultiplierFacetStorage.LayoutA reference to the Layout struct in storage.
nftIduint256The unique identifier of the NFT associated with the position.
amountOfPacketsuint256The number of packets to account for.

Return Values

NameTypeDescription
[0]uint256The virtual balance of the specified packets accounting only for any applicable lock multiplier.