yStaking Module
Module Overview
The YStaking
module of the PRYZM network empowers users to yield rewards through staking their yASSET. The key functions of this module include "Bond", "Unbond", and "ClaimReward". These functions facilitate user participation in the staking process, allow withdrawal of their stake, and claim earned rewards respectively.
Concepts
YAsset Pool
A yAsset pool manages staked yield tokens of a specific asset in the YStaking module. Each yAsset pool tracks the bondedAmount
and globalIndex
for an ASSET. Note that, bondedAmount
represents the total yASSET amount of a specific ASSET across all active maturity levels (expired maturities are not included in the bondedAmount
). The globalIndex
value, used for reward calculations, indicates the reward amount accrued to the pool relative to the bondedAmount
. When a reward of amount is accrued to the pool, the globalIndex
is updated as follows:
Here, and are the globalIndex
values before and after the reward respectively, and is the bondedAmount
for the pool. The initial value of the globalIndex
is .
To manage different asset maturities, the yAsset pool also keeps track of certain parameters for each maturity using MaturityYAssetPool
pools. A yAsset pool maintains a registry of active and inactive maturities related to its MaturityYAssetPool
s. The pool marks maturities as inactive when the Assets Module triggers the listeners for maturity deactivation. More details about deactivating a maturity are explained in the listeners section. The yAsset pool also provides an API for retrieving a MaturityYAssetPool
by its symbol and active state.
Maturity YAsset Pool
Each yAsset pool maintains a set of maturity yAsset pools according to the asset maturities. A maturity yAsset pool holds the bondedAmount
and globalIndex
values for its specific asset and maturity. Additionally, it tracks staked tokens for users. For each user, a maturity yAsset pool holds bondedAmount
, userIndex
, and pendingReward
(if they have some bonded amount or reward to claim). The bondedAmount
represents the precise staked amount of yASSET with the specific maturity of this pool for a specific user. The userIndex
and pendingReward
are used for reward computations and will be explained in subsequent sections. A maturity yAsset pool provides APIs for bond
, unbond
, claimReward
, and exitPool
.
Bond
Bonding refers to a user staking a specific amount of a yAsset of a specific maturity. The bond API is provided by MaturityYAssetPool
, which can be accessed from the related YAssetPool
by providing the maturity symbol. Notably, bonding is only available for active maturities, and tokens of expired maturities cannot be bonded. When a user bonds a value of to a MaturityYAssetPool
, the parameters of the related pools are updated as follows:
- The
bondedAmount
of theYAssetPool
increases by the bonded amount:
Here, and represent the bondedAmount
parameter before and after the ongoing bond respectively.
- The
bondedAmount
of theMaturityYAssetPool
also increases by the bonding amount. - The
pendingReward
for the user in the specificMaturityYAssetPool
is updated as:
In this formula, and denote the pendingReward
for user before and after the bond related to this specific asset and maturity. The term signifies the bondedAmount
for user of this particular asset and maturity before the bond. The variable represents the globalIndex
of the asset, while signifies the userIndex
for user prior to this bond. Note: The initial value for is , and the initial value for is equal to .
- The
bondedAmount
of the user within theMaturityYAssetPool
also increases by the bond amount.
- The
userIndex
for this asset and maturity matches theglobalIndex
of the asset.
Unbond
Unbonding involves a user unstaking a quantity of a yAsset of a specific maturity. As previously mentioned, the Unbond API is supplied by MaturityYAssetPool
, which can be retrieved from the corresponding YAssetPool
by providing the maturity symbol. Note: Unbonding is only permitted for active maturities. For expired maturities, use the ExitPool function. A user's unbonding of value from a MaturityYAssetPool
updates the parameters of the related pools as follows, and may result in a reward being paid to the user:
- The
bondedAmount
of theYAssetPool
is reduced by the unbonded amount:
Here, and depict the bondedAmount
parameter before and after the unbonding respectively.
- The
bondedAmount
of theMaturityYAssetPool
also decreases by the unbonded amount. - The user receives a reward for their bonded amount up until this unbond:
In this equation, designates the reward amount to be paid. Note: As outlined in the Treasury module, a fee is deducted from this reward, with the remainder paid to the user.
- The
pendingReward
for the user in the specificMaturityYAssetPool
is reset to zero:
- The
bondedAmount
of the user in theMaturityYAssetPool
is also reduced by the unbonded amount.
- The
userIndex
for this asset and maturity matches theglobalIndex
of the asset.
It's important to note that if a user's new bonded amount reaches zero after unbonding, the user state will be removed to minimize storage footprint.
ClaimReward
Claiming a reward is a process where a user can claim the accrued reward for their bonded amount of a specific asset and maturity. The MaturityYAssetPool
provides the ClaimReward API, which is accessible from the corresponding YAssetPool
by passing the maturity symbol. Keep in mind, claiming rewards is only possible for active maturities. For expired maturities, users must utilize the ExitPool method. When a user claims a reward for a particular asset and maturity, several actions occur:
- The user receives the appropriate reward for their bonded amount until this unbond:
Here, denotes the reward amount to be paid. Note: As discussed in the Treasury Module, a fee is deducted from this reward, and the remainder is paid to the user.
- The user's
pendingReward
in the specificMaturityYAssetPool
is reset to zero:
- The
userIndex
for this asset and maturity synchronizes with theglobalIndex
of the asset.