ContinuousVirtualLockMultiplierFacetStorage
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 a continuous-based schema.
_Example of an continuous-based schema configuration:
If timeLockPeriods = [100, 200, 300]
and timeLockMultipliers = [2, 3, 4]
:
-
A position with lock duration less than 100 seconds will receive a lock multiplier of 1 (no multiplier).
-
A position with lock duration X seconds, where X is between 100 (inclusive) and 200 (exclusive), will receive a lock multiplier calculated as follows:
lockMultiplierForX = 2 + ((X - 100) / (200 - 100)) * (3 - 2)
-
A position with lock duration Y seconds, where Y is between 200 (inclusive) and 300 (exclusive), will receive a lock multiplier calculated as follows:
lockMultiplierForY = 3 + ((Y - 200) / (300 - 200)) * (4 - 3)
-
A position with lock duration 300 seconds or more will receive a lock multiplier of 4.
IMPORTANT:
- Multipliers should be scaled by 1e18, allowing for calculations with up to 18 decimal precision.
-
timeLockPeriods
andtimeLockMultipliers
must be in strictly increasing order._
CampaignNotOnCreationStateForSetting
Thrown when a targeted campaign is not "On Creation" state, which is required at configurations.
NoTimeLockMultiplierDataProvided
Thrown at setter when no data provided for either timeLockPeriods
or timeLockMultipliers
.
InvalidTimeLockMultiplierDataLengths
Thrown at setter when the lengths of timeLockPeriods
and timeLockMultipliers
do not match.
InvalidZeroFirstTimeLockMultiplierData
Thrown at setter when the first element of timeLockPeriods
or timeLockMultipliers
is zero.
InvalidTimeLockMultiplierDataOrder
Thrown at setter when the timeLockPeriods
or timeLockMultipliers
are not in strictly increasing order.
STORAGE_SLOT
Unique identifier for the storage slot where the Layout struct is stored.
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.
CampaignInfo
Struct containing the configuration information for lock-wise multipliers in a staking campaign.
layout
Retrieves a reference to the Layout struct stored at the slot specified by STORAGE_SLOT
unique identifier.
setCampaignVirtualLockMultipliers
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
Name | Type | Description |
---|---|---|
l | struct ContinuousVirtualLockMultiplierFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
campaignVirtualLockMultipliersData | bytes | The 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
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
Name | Type | Description |
---|---|---|
l | struct ContinuousVirtualLockMultiplierFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
nftId | uint256 | The unique identifier of the NFT associated with the position. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | The value of the applied lock multiplier. |
combineVirtualLockMultipliers
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
Name | Type | Description |
---|---|---|
l | struct ContinuousVirtualLockMultiplierFacetStorage.Layout | A reference to the Layout struct in storage. |
nftId | uint256 | The unique identifier of the NFT associated with the position. |
currentLockMultiplier | uint256 | The value of the lock multiplier currently applied to the position. |
newLockMultiplier | uint256 | The lock multiplier applicable for the restake's lock period. |
packetsStaked | uint256 | The total amount of staked input packets in the current position. |
packetsRestaked | uint256 | The amount of input packets to be allocated during the restake operation. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | The calculated combined lock multiplier value. |
calculateVirtualLockMultiplier
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
Name | Type | Description |
---|---|---|
l | struct ContinuousVirtualLockMultiplierFacetStorage.Layout | A reference to the Layout struct in storage. |
campaignId | uint256 | The unique identifier of the targeted staking campaign. |
timeLockPeriod | uint256 | The lock duration for which the multiplier will be calculated. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | The calculated lock multiplier value. |
getVirtualBalance
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
Name | Type | Description |
---|---|---|
l | struct ContinuousVirtualLockMultiplierFacetStorage.Layout | A reference to the Layout struct in storage. |
nftId | uint256 | The unique identifier of the NFT associated with the position. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | The virtual balance of the position accounting for both any applicable amount and lock multipliers. |
getVirtualBalanceForAmount
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
Name | Type | Description |
---|---|---|
l | struct ContinuousVirtualLockMultiplierFacetStorage.Layout | A reference to the Layout struct in storage. |
nftId | uint256 | The unique identifier of the NFT associated with the position. |
amountOfPackets | uint256 | The number of packets to account for. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | The virtual balance of the specified packets accounting only for any applicable lock multiplier. |