core staking contracts
PriorityPool Contract: Staking Queue and Liquidity Buffer
The PriorityPool allows users to queue asset tokens which are eventually deposited into a StakingPool when deposit room becomes available. The liquid staking tokens (LSTs) minted by the StakingPool are then distributed using a merkle tree.
Each user will continuously receive LSTs as more deposits are made into the StakingPool until they have received an amount equal to the amount of asset tokens they deposited into the PriorityPool. The rate at which each user receives LSTs is dependent on the userâs reSDL balance in the SDLPool. A higher reSDL balance entitles the user to receive LSTs at a faster rate than a user with a smaller reSDL balance. Users that hold no reSDL can also deposit into the PriorityPool but they will receive no LSTs as long as there are users with deposits in the PriorityPool that also hold reSDL.
The secondary function of the PriorityPool is to act as a liquidity buffer for the StakingPool it deposits into. When a user redeems LSTs for the underlying asset token, these LSTs will be swapped with queued asset tokens from the PriorityPool if possible before queuing tokens in the WithdrawalPool. This both reduces gas costs for the user and ensures that the StakingPool earns the most yield possible as yield earning asset tokens remain in the pool instead of being withdrawn.
View Functions
Section titled âView FunctionsâReturns the address of the token this pool handles
function token() external view returns (address)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| token | address | address of token |
stakingPool
Section titled âstakingPoolâReturns the address of the staking pool that this pool deposits into
function stakingPool() external view returns (address)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| stakingPool | address | address of staking pool |
sdlPool
Section titled âsdlPoolâReturns the address of the SDL pool
function sdlPool() external view returns (address)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| sdlPool | address | address of SDL pool |
distributionOracle
Section titled âdistributionOracleâReturns the address of the oracle that handles distribution of liquid staking tokens
function distributionOracle() external view returns (address)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| distributionOracle | address | address of distribution oracle |
rebaseController
Section titled ârebaseControllerâReturns the address of the rebase controller
function rebaseController() external view returns (address)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| rebaseController | address | address of rebase controller |
withdrawalPool
Section titled âwithdrawalPoolâReturns the address of the withdrawal pool
function withdrawalPool() external view returns (address)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| withdrawalPool | address | address of withdrawal pool |
queueDepositMin
Section titled âqueueDepositMinâReturns the minimum amount of tokens required to execute a deposit
function queueDepositMin() external view returns (uint256)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| depositMin | uint256 | queue deposit minimum |
queueDepositMax
Section titled âqueueDepositMaxâReturns the maximum amount of tokens that can be deposited in a single deposit
function queueDepositMax() external view returns (uint256)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| depositMax | uint256 | queue deposit maximum |
poolStatus
Section titled âpoolStatusâReturns the current status of the pool
0 - OPEN (nothing disabled)
1 - DRAINING (deposits disabled)
2 - CLOSED (deposits/withdrawals disabled)
function poolStatus() external view returns (PoolStatus)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| poolStatus | PoolStatus | current status of the pool |
merkleRoot
Section titled âmerkleRootâReturns the merkle root for the latest distribution tree
function merkleRoot() external view returns (bytes32)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| merkleRoot | bytes32 | current merkle root |
ipfsHash
Section titled âipfsHashâReturns the ipfs hash of the balance data for the latest distribution tree
function ipfsHash() external view returns (bytes32)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| ipfsHash | bytes32 | current ipfsHash |
merkleTreeSize
Section titled âmerkleTreeSizeâReturns the number of unique addresses contained in the latest distribution tree
function merkleTreeSize() external view returns (uint256)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| merkleTreeSize | uint256 | current merkle tree size |
totalQueued
Section titled âtotalQueuedâReturns the total amount of token deposits in the pool waiting to be deposited into the staking pool
function totalQueued() external view returns (uint256)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| totalQueued | uint256 | total deposits in the pool |
getAccounts
Section titled âgetAccountsâReturns a list of all accounts that have deposited into the pool in the order that they appear in the distribution tree
function getAccounts() external view returns (address[])Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| accounts | address[] | list of accounts |
getAccountIndex
Section titled âgetAccountIndexâReturns the index of an account representing itâs position in the distribution tree
function getAccountIndex(address _account) external view returns (uint256)Parameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _account | address | account address |
Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| index | uint256 | account index |
getQueuedTokens
Section titled âgetQueuedTokensâReturns an accountâs current amount of deposits in the pool (_distributionAmount is stored on IPFS)
function getQueuedTokens(address _account, uint256 _distributionAmount) public view returns (uint256)Parameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _account | address | account address |
| _distributionAmount | uint256 | accountâs distribution amount from the latest distribution tree |
Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| queuedTokens | uint256 | amount of queued tokens for account |
getLSDTokens
Section titled âgetLSDTokensâReturns an accountâs current amount of withdrawable liquid staking tokens (_distributionShareAmount is stored on IPFS)
function getLSDTokens(address _account, uint256 _distributionShareAmount) external view returns (uint256)Parameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _account | address | account address |
| _distributionShareAmount | uint256 | accountâs distribution share amounts from the latest distribution tree |
Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| lsdTokens | uint256 | withdrawable LSD tokens for account |
getLSDTokensBatch
Section titled âgetLSDTokensBatchâReturns the current amount of withdrawable LSD tokens for multiple accounts.
function getLSDTokensBatch(address[] calldata _accounts, uint256[] calldata _distributionShareAmounts) external view returns (uint256[] memory)Parameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _accounts | address[] | List of account addresses |
| _distributionShareAmounts | uint256[] | Distribution share amounts for each account |
Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| lsdTokens | uint256[] | Withdrawable LSD tokens for accounts |
canWithdraw
Section titled âcanWithdrawâReturns the total amount of asset tokens that an account can withdraw (includes accountâs queued tokens and stLINK balance and takes into account both priority pool and staking pool liquidity)
function canWithdraw(address _account, uint256 _distributionAmount) external view returns (uint256)Parameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _account | address | account address |
| _distributionAmount | uint256 | accountâs distribution amount from the latest distribution tree |
Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| canWithdraw | uint256 | amount of withdrawable tokens |
checkUpkeep
Section titled âcheckUpkeepâReturns whether a call should be made to performUpkeep to deposit queued/unused tokens
into staking pool strategies
function checkUpkeep(bytes) external view returns (bool, bytes)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| upkeepNeeded | bool | whether a call should be made to performUpkeep |
| upkeepNeeded | bytes | encoded amount of tokens to be deposited |
getDepositsSinceLastUpdate
Section titled âgetDepositsSinceLastUpdateâReturns the amount of new deposits into the staking pool since the last call to updateDistribution and the amount of shares received for those deposits
function getDepositsSinceLastUpdate() external view returns (uint256, uint256)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| deposits | uint256 | amount of deposits |
| shares | uint256 | amount of shares |
getAccountData
Section titled âgetAccountDataâReturns account data used for calculating a new merkle tree
A new merkle tree is calculated based on usersâ reSDL balance and the number of tokens they have queuedAccounts are returned in the same order as they are in the merkle tree
function getAccountData() external view returns (address[], uint256[], uint256[])Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| accounts | address[] | list of all accounts that have ever queued tokens |
| sdlBalances | uint256[] | list of SDL balances for each account |
| queuedBalances | uint256[] | list of queued token amounts for each account (ignores distributed LSD tokens) |
Write Functions
Section titled âWrite FunctionsâonTokenTransfer
Section titled âonTokenTransferâERC677 implementation to receive a token deposit or withdrawal
Can receive both asset tokens (deposit) and liquid staking tokens (withdrawal)
function onTokenTransfer(address _sender, uint256 _value, bytes _calldata) externalParameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _sender | address | sender of the transfer |
| _value | uint256 | value of the transfer |
| _calldata | bytes | encoded shouldQueue (bool) and deposit data to pass to staking pool strategies (bytes[]) |
deposit
Section titled âdepositâDeposits asset tokens into the staking pool and/or queues them
function deposit(uint256 _amount, bool _shouldQueue, bytes _data) externalParameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _amount | uint256 | amount to deposit |
| _shouldQueue | bool | whether tokens should be queued if thereâs no room in the staking pool |
| _data | bytes | deposit data passed to staking pool strategies |
withdraw
Section titled âwithdrawâWithdraws asset tokens
Will unqueue senderâs asset tokens before swapping liquid staking tokens if there is sufficient liquidity and _shouldUnqueue is set to true
function withdraw(uint256 _amountToWithdraw, uint256 _amount, uint256 _sharesAmount, bytes32[] _merkleProof, bool _shouldUnqueue, bool _shouldUnqueueWithdrawal) externalParameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _amountToWithdraw | uint256 | amount of tokens to withdraw |
| _amount | uint256 | amount as recorded in senderâs merkle tree (stored on IPFS)entry |
| _sharesAmount | uint256 | shares amount as recorded in senderâs merkle tree (stored on IPFS)entry |
| _merkleProof | bytes32[] | merkle proof for senderâs merkle tree entry (generated from IPFS data) |
| _shouldUnqueue | bool | whether tokens should be unqueued before taking LSD tokens |
| _shouldQueueWithdrawal | bool | whether a withdrawal should be queued if the full withdrawal amount cannot be satisfied |
unqueueTokens
Section titled âunqueueTokensâWithdraws queued deposits from the priority pool
function unqueueTokens(uint256 _amountToUnqueue, uint256 _amount, uint256 _sharesAmount, bytes32[] _merkleProof) externalParameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _amountToUnqueue | uint256 | amount of tokens to unqueue |
| _amount | uint256 | amount as recorded in senderâs merkle tree entry (stored on IPFS) |
| _sharesAmount | uint256 | shares amount as recorded in senderâs merkle tree entry (stored on IPFS) |
| _merkleProof | bytes32[] | merkle proof for senderâs merkle tree entry (generated from IPFS data) |
claimLSDTokens
Section titled âclaimLSDTokensâClaims withdrawable liquid staking tokens
function claimLSDTokens(uint256 _amount, uint256 _sharesAmount, bytes32[] _merkleProof) externalParameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _amount | uint256 | amount as recorded in senderâs merkle tree entry |
| _sharesAmount | uint256 | shares amount as recorded in senderâs merkle tree entry |
| _merkleProof | bytes32[] | merkle proof for senderâs merkle tree entry |
depositQueuedTokens
Section titled âdepositQueuedTokensâDeposits queued tokens and/or unused tokens sitting in staking pool
function depositQueuedTokens(uint256 _queueDepositMin, uint256 _queueDepositMax, bytes[] _data) externalParameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _queueDepositMin | uint256 | min amount of tokens required for deposit into staking pool strategies |
| _queueDepositMax | uint256 | max amount of tokens that can be deposited into staking pool strategies at once |
| _data | bytes[] | list of deposit data passed to staking pool strategies |
performUpkeep
Section titled âperformUpkeepâDeposits queued and/or unused tokens
function performUpkeep(bytes _performData) externalParameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _performData | bytes[] | encoded list of deposit data to be passed to staking pool strategies (bytes[]) |
updateDistribution
Section titled âupdateDistributionâDistributes a new batch of liquid staking tokens to users that have queued deposits
function updateDistribution(bytes32 _merkleRoot, bytes32 _ipfsHash, uint256 _amountDistributed, uint256 _sharesAmountDistributed) externalParameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _merkleRoot | bytes32 | new merkle root for the distribution tree |
| _ipfsHash | bytes32 | new ipfs hash for the distribution tree (CIDv0, no prefix - only hash) |
| _amountDistributed | uint256 | amount of LSD tokens distributed in this distribution |
| _sharesAmountDistributed | uint256 | amount of LSD shares distributed in this distribution |
executeQueuedWithdrawals
Section titled âexecuteQueuedWithdrawalsâExecutes a batch of withdrawals that have been queued in the withdrawal pool
Withdraws tokens from the staking pool and sends them to the withdrawal pool
function executeQueuedWithdrawals(uint256 _amount, bytes[] _data) externalParameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _amount | uint256 | total amount to withdraw |
| _data | bytes | list of withdrawal data passed to staking pool strategies |
pauseForUpdate
Section titled âpauseForUpdateâPauses queueing and unqueueing so a new merkle tree can be generated
function pauseForUpdate() externalsetPoolStatus
Section titled âsetPoolStatusâSets the poolâs status
function setPoolStatus(enum PriorityPool.PoolStatus _status) externalParameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _status | PoolStatus | pool status |
setQueueDepositParams
Section titled âsetQueueDepositParamsâSets the minimum and maximum amount that can be deposited into strategies at once
function setQueueDepositParams(uint128 _queueDepositMin, uint128 _queueDepositMax) externalParameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _queueDepositMin | uint128 | minimum amount of tokens required for deposit into staking pool strategies |
| _queueDepositMax | uint128 | maximum amount of tokens that can be deposited into staking pool strategies at once |
setDistributionOracle
Section titled âsetDistributionOracleâSets the distribution oracle
function setDistributionOracle(address _distributionOracle) externalParameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _distributionOracle | address | address of oracle |
setRebaseController
Section titled âsetRebaseControllerâSets the rebase controller
This address has authorization to close the pool in case of emergency
function setRebaseController(address _rebaseController_) externalParameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _rebaseController | address | address of rebase controller |
setWithdrawalPool
Section titled âsetWithdrawalPoolâSets the withdrawal pool
function setWithdrawalPool(address _withdrawalPool) externalParameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _withdrawalPool | address | address of withdrawal pool |
setAllowInstantWithdrawals
Section titled âsetAllowInstantWithdrawalsâSets whether instant withdrawals are enabled.
function setAllowInstantWithdrawals(bool _allowInstantWithdrawals) externalParameters
Section titled âParametersâ| Name | Type | Description |
|---|---|---|
| _allowInstantWithdrawals | bool | Whether instant withdrawals enabled |
allowInstantWithdrawals
Section titled âallowInstantWithdrawalsâReturns whether instant withdrawals are enabled.
function allowInstantWithdrawals() external view returns (bool)Return Values
Section titled âReturn Valuesâ| Name | Type | Description |
|---|---|---|
| allowInstantWithdrawals | bool | Whether instant withdrawals enabled |