Staking
StakingProxy
is proxy, and its implementation is StakingPackage
.
The Staking Package is designed for creating and managing staking streams, handling user stakes with the ability to lock and unlock tokens, and calculating rewards. The contract allows for the addition of new staking streams, each with unique parameters like reward schedules and lock periods. It also enforces rules around the early withdrawal of stakes, calculating penalties, and distributing rewards, ensuring a robust and flexible staking environment.
State Variables
mainStreamInitialized
:
mainStreamInitialized
:Type:
bool
Description: Indicates whether the main stream has been initialized.
MAIN_STREAM
:
MAIN_STREAM
:Type:
uint256
Description: The constant identifier for the main staking stream.
streams
:
streams
:Type:
Stream[]
Description: Dynamic array storing all streams available for staking.
locks
:
locks
:Type:
mapping(address => LockedBalance[])
Description: Maps user addresses to their respective locked balances.
users
:
users
:Type:
mapping(address => User)
Description: Maps user addresses to their staking-related data.
streamTotalUserPendings
:
streamTotalUserPendings
:Type:
mapping(uint256 => uint256)
Description: Maps stream IDs to total pending tokens for users.
prohibitedEarlyWithdraw
:
prohibitedEarlyWithdraw
:Type:
mapping(address => mapping(uint256 => bool))
Description: Tracks locks that cannot be unlocked early.
totalAmountOfStakedToken
, totalStreamShares
, totalAmountOfVoteToken
:
totalAmountOfStakedToken
, totalStreamShares
, totalAmountOfVoteToken
:Type:
uint256
Description: Track the total amounts of staked tokens, stream shares, and vote tokens across all users.
totalPenaltyBalance
:
totalPenaltyBalance
:Type:
uint256
Description: Sum of all penalties collected from early withdrawals.
vault
, treasury
, rewardsCalculator
, mainToken
, voteToken
:
vault
, treasury
, rewardsCalculator
, mainToken
, voteToken
:Type:
address
Description: Addresses of contracts for the vault, treasury, rewards calculation, main token, and voting token.
minLockPeriod
, maxLockPeriod
:
minLockPeriod
, maxLockPeriod
:Type:
uint256
Description: The minimum and maximum lock periods for staking tokens.
maxLockPositions
:
maxLockPositions
:Type:
uint256
Description: Maximum number of lock positions a user can have.
Structs
Schedule:
time
: An array of timestamps indicating the start of each reward distribution interval. The last timestamp marks the stream's end.reward
: An array parallel totime
, specifying the amount of rewards at the start of each interval. The final entry is always zero, marking the end of rewards.
User:
voteTokenBalance
: Represents the total balance of voting tokens a user possesses.pendings
: A mapping from a stream ID to the amount of tokens pending release for the user.releaseTime
: A mapping from a stream ID to the timestamp when tokens are scheduled for release.rpsDuringLastClaimForLock
: Nested mappings from stream ID and lock ID to the reward-per-share value noted at the last claim.
Weight:
maxWeightShares
,minWeightShares
: Used to calculate the share weight over time from maximum to minimum.maxWeightPenalty
,minWeightPenalty
,penaltyWeightMultiplier
: Parameters for calculating early withdrawal penalties.
VoteCoefficient:
voteShareCoef
,voteLockCoef
: Coefficients influencing the voting power derived from token shares and lock duration, respectively.
LockedBalance:
amountOfToken
,positionStreamShares
: Tokens locked and shares of the position within a stream, respectively.end
: The expiration of the lock.owner
: The owner of the lock.amountOfVoteToken
: Amount of vote tokens reflecting the voting power from this lock.
Stream:
Contains properties such as the owner, the manager, reward token type, status, financial thresholds, schedule data, and others. Status is managed through an enum (
StreamStatus
), which tracks if a stream is active, proposed, or inactive.
CreateLockParams:
Details required to create a lock:
amount
of tokens,lockPeriod
, and theaccount
the lock is associated with.
Set Functions
createLock
createLock
Arguments:
uint256 amount
: The amount of tokens to be locked.uint256 lockPeriod
: The period for which the tokens are locked.
Returns:
No return value. This function processes the locking of tokens and interacts with the internal state.
unlock
unlock
Arguments:
uint256 lockId
: The identifier of the lock to be unlocked.
Returns:
No return value. This function processes the unlocking of tokens, updating the internal state to reflect the change.
unlockPartially
unlockPartially
Arguments:
uint256 lockId
: The identifier of the lock to be partially unlocked.uint256 amount
: The amount of tokens to unlock from the specified lock.
Returns:
No return value. This function allows partial unlocking of locked tokens and modifies the internal state accordingly.
earlyUnlock
earlyUnlock
Arguments:
uint256 lockId
: The identifier of the lock to be unlocked early.
Returns:
No return value. It handles the early unlocking process, adjusting the user's locked tokens and any applicable penalties.
claimAllStreamRewardsForLock
claimAllStreamRewardsForLock
Arguments:
uint256 lockId
: The identifier of the lock for which all stream rewards are claimed.
Returns:
No return value. This function processes the claiming of all rewards associated with a particular lock.
claimAllLockRewardsForStream
claimAllLockRewardsForStream
Arguments:
uint256 streamId
: The identifier of the stream for which all rewards for all locks are claimed.
Returns:
No return value. It handles the claiming of rewards for all locks associated with a specific stream.
withdrawStream
withdrawStream
Arguments:
uint256 streamId
: The identifier of the stream from which to withdraw rewards.
Returns:
No return value. This function processes the withdrawal of rewards from a specific stream.
withdrawAllStreams
withdrawAllStreams
Arguments:
None.
Returns:
No return value. This function facilitates the withdrawal of rewards from all streams associated with the caller.
Events
Staked
Staked
Emitted when: A new lock is created and tokens are staked.
Parameters:
address indexed account
: The account that staked tokens.uint256 amount
: The amount of tokens staked.uint256 streamShares
: Shares received in the stream due to staking.uint256 nVoteToken
: Number of voting tokens allocated.uint256 indexed lockId
: The identifier of the lock.uint256 end
: When the lock will end.
StreamProposed
StreamProposed
Emitted when: A new stream is proposed.
Parameters:
uint256 indexed streamId
: Identifier of the proposed stream.address indexed streamOwner
: The owner of the stream.address indexed rewardToken
: The token used for rewards in the stream.uint256 maxDepositAmount
: The maximum amount that can be deposited in the stream.
Released
Released
Emitted when: Tokens are released from a stream.
Parameters:
uint256 indexed streamId
: The stream from which tokens are released.address indexed user
: The user receiving the released tokens.uint256 pendingAmount
: The amount of tokens released.
StreamProposalCancelled
StreamProposalCancelled
Emitted when: A proposed stream is cancelled.
Parameters:
uint256 indexed streamId
: The stream that was cancelled.address indexed owner
: Owner of the stream.address indexed token
: The reward token associated with the cancelled stream.
StreamCreated
StreamCreated
Emitted when: A stream is created and becomes active.
Parameters:
uint256 indexed streamId
: The identifier of the created stream.address indexed owner
: The owner of the stream.address indexed token
: The reward token of the stream.uint256 tau
: The pending time prior reward release for the stream.
StreamRemoved
StreamRemoved
Emitted when: A stream is removed.
Parameters:
uint256 indexed streamId
: The identifier of the removed stream.address indexed owner
: The owner of the stream.address indexed token
: The reward token of the removed stream.
Unstaked
Unstaked
Emitted when: A full unlock is performed on a lock.
Parameters:
address indexed account
: The account that unstaked tokens.uint256 amount
: The amount of tokens unstaked.uint256 indexed lockId
: The identifier of the lock from which tokens were unstaked.
PartialUnstaked
PartialUnstaked
Emitted when: A partial unlock is performed on a lock.
Parameters:
address indexed account
: The account that partially unstaked tokens.uint256 amount
: The amount of tokens unstaked.uint256 indexed lockId
: The identifier of the lock from which tokens were partially unstaked.
Pending
Pending
Emitted when: Rewards are moved to pending for a user in a stream.
Parameters:
uint256 indexed streamId
: The stream where rewards are pending.address indexed account
: The user for whom rewards are pending.uint256 pendings
: Amount of tokens that are pending.
Last updated