StMATIC
StMATIC is the core contract which acts as a liquid staking pool. The contract is responsible for deposits, withdrawals, minting and burning liquid tokens, delegating funds to node operators, applying fees and distributing rewards.
StMATIC contract also defines stMATIC, an ERC20 token that represents the account's share of the total supply of MATIC tokens inside Lido on Polygon system. It is a non-rebasable token, which means that the amount of tokens in the user's wallet is not going to change. During time, the value of this token is changing, since the amount of MATIC tokens inside the protocol is not constant. StMATIC will be integrated in variety of DeFi applications across Ethereum and Polygon.
View Methods
name()
Returns the name of the token
function name() returns (string)
symbol()
Returns the symbol of the token, usually a shorter version of the name
function symbol() returns (string)
decimals()
Returns the number of decimals for getting user representation of a token amount.
function decimals() returns (uint8)
totalSupply()
Returns the amount of tokens in existence.
function totalSupply() returns (uint256)
balanceOf()
Returns the amount of tokens owned by the _account
function balanceOf(address _account) returns (uint256)
getTotalStake()
Returns the total amount of stake the StMatic contract has in a validator
function getTotalStake(IValidatorShare _validatorShare)
public
view
override
returns (uint256, uint256)
Parameters:
Name | Type | Description |
---|---|---|
_validatorShare | ValidatorShare | An instance of the validator share contract |
Returns:
Name | Type | Description |
---|---|---|
totalStake | uint256 | The total staked in the validator |
getLiquidRewards()
Returns the reward accumulated by the StMATIC contract in a specific validator share.
function getLiquidRewards(IValidatorShare _validatorShare)
external
view
override
returns (uint256)
Parameters:
Name | Type | Description |
---|---|---|
_validatorShare | ValidatorShare | An instance of the validator share contract |
Returns:
Name | Type | Description |
---|---|---|
rewards | uint256 | The total rewards accumulated inside the validatorShare contract |
getTotalStakeAcrossAllValidators()
Returns the total delegated MATICs across all validators.
function getTotalStakeAcrossAllValidators()
public
view
override
returns (uint256)
Returns:
Name | Type | Description |
---|---|---|
total | uint256 | The total delegated MATICs across all validators |
getTotalPooledMatic()
Returns total pooled matic
function getTotalPooledMatic() public view override returns (uint256)
Returns:
Name | Type | Description |
---|---|---|
total | uint256 | The total pooled matic inside the protocol |
convertStMaticToMatic()
Returns the MATIC value of any StMatic amount passed to the function
function convertStMaticToMatic(uint256 _amountInStMatic)
public
view
override
returns (
uint256 amountInMatic,
uint256 totalStMaticAmount,
uint256 totalPooledMatic
)
Parameters:
Name | Type | Description |
---|---|---|
_amountInStMatic | uint256 | Amount of StMatic to be convert to MATIC |
Returns:
Name | Type | Description |
---|---|---|
amountInMatic | uint256 | Amount of Matic after conversion |
totalStMaticAmount | uint256 | Total StMatic in the contract |
totalPooledMatic | uint256 | Total Matic in the staking pool |
convertMaticToStMatic
Returns the StMatic value of any MATIC amount passed to the function
function convertMaticToStMatic(uint256 _amountInMatic)
public
view
override
returns (
uint256 amountInStMatic,
uint256 totalStMaticAmount,
uint256 totalPooledMatic
)
Parameters:
Name | Type | Description |
---|---|---|
_amountInMatic | uint256 | Amount of MATIC to be convert to StMatic |
Returns:
Name | Type | Description |
---|---|---|
amountInStMatic | uint256 | Amount of stMatic after conversion |
totalStMaticAmount | uint256 | Total StMatic in the contract |
totalPooledMatic | uint256 | Total Matic in the staking pool |
getToken2WithdrawRequests()
Returns the list of requestWithdraw attached with a tokenId.
function getToken2WithdrawRequests(uint256 _tokenId)
external
view
returns (RequestWithdraw[] memory)
Parameters:
Name | Type | Description |
---|---|---|
_tokenId | uint256 | NFT token ID |
Returns:
Name | Type | Description |
---|---|---|
requestWithdraw | RequestWithdraw[] | list of request withdraw |
getMaticFromTokenId()
Returns the amount of MATIC that will be claimed from an NFT token
function getMaticFromTokenId(uint256 _tokenId)
external
view
override
returns (uint256)
Parameters:
Name | Type | Description |
---|---|---|
_tokenId | uint256 | NFT token ID |
Returns:
Name | Type | Description |
---|---|---|
amount | uint256 | Amount of matic to get after claim the token |
Methods
transfer()
Moves _amount
tokens from the caller's account to the _recipient
account.
function transfer(address _recipient, uint256 _amount) returns (bool)
Requirements:
_recipient
cannot be the zero address.- the caller must have a balance of at least
_amount
. - the contract must not be paused.
Parameters:
Name | Type | Description |
---|---|---|
_recipient | address | Address of tokens recipient |
_amount | uint256 | Amount of tokens to transfer |
Returns:
A boolean value indicating whether the operation succeeded.
allowance()
Returns the remaining number of tokens that _spender
is allowed to spend
on behalf of _owner
through transferFrom
. This is zero by default.
function allowance(address _owner, address _spender) returns (uint256)
This value changes when approve
or transferFrom
is called.
Parameters:
Name | Type | Description |
---|---|---|
_owner | address | Address of owner |
_spender | address | Address of spender |
approve()
Sets _amount
as the allowance of _spender
over the caller's tokens
function approve(address _spender, uint256 _amount) returns (bool)
Requirements:
_spender
cannot be the zero address.- the contract must not be paused.
Parameters:
Name | Type | Description |
---|---|---|
_spender | address | Address of spender |
_amount | uint256 | Amount of tokens |
Returns:
A boolean value indicating whether the operation succeeded
transferFrom()
Moves _amount
tokens from _sender
to _recipient
using the
allowance mechanism. _amount
is then deducted from the caller's
allowance.
function transferFrom(
address _sender,
address _recipient,
uint256 _amount
) returns (bool)
Requirements:
_sender
and_recipient
cannot be the zero addresses._sender
must have a balance of at least_amount
.- the caller must have allowance for
_sender
's tokens of at least_amount
. - the contract must not be paused.
Parameters:
Name | Type | Description |
---|---|---|
_sender | address | Address of spender |
_recipient | address | Address of recipient |
_amount | uint256 | Amount of tokens |
Returns:
A boolean value indicating whether the operation succeeded
increaseAllowance()
Atomically increases the allowance granted to _spender
by the caller by _addedValue
This is an alternative to approve
that can be used as a mitigation for problems described here
function increaseAllowance(address _spender, uint256 _addedValue) returns (bool)
Requirements:
_spender
cannot be the the zero address.- the contract must not be paused.
Parameters:
Name | Type | Description |
---|---|---|
_sender | address | Address of spender |
_addedValue | uint256 | Amount of tokens to increase allowance |
Returns:
Returns a boolean value indicating whether the operation succeeded
decreaseAllowance()
Atomically decreases the allowance granted to _spender
by the caller by _subtractedValue
This is an alternative to approve
that can be used as a mitigation for
problems described here
function decreaseAllowance(address _spender, uint256 _subtractedValue) returns (bool)
Requirements:
_spender
cannot be the zero address._spender
must have allowance for the caller of at least_subtractedValue
.- the contract must not be paused.
Parameters:
Name | Type | Description |
---|---|---|
_sender | address | Address of spender |
_subtractedValue | uint256 | Amount of tokens to decrease allowance |
Returns:
Returns a boolean value indicating whether the operation succeeded
submit()
Send MATIC to the StMATIC contract and mints stMATIC to msg.sender. The user has first to approve the amount to the StMATIC contract.
function submit(uint256 _amount, address _referral)
external
override
whenNotPaused
returns (uint256)
Parameters:
Name | Type | Description |
---|---|---|
_amount | uint256 | Amount to submit in MATIC |
_referral | address | Referral address |
Returns:
Name | Type | Description |
---|---|---|
_amount | uint256 | Amount of stMATIC |
requestWithdraw()
Allows users to request withdrawal of an amount of Matic tokens depending on the amount submitted of stMATIC. This will mint a Lido NFT token which can be used later to claim the amount.
function requestWithdraw(uint256 _amount, address _referral) external override returns returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_amount | uint256 | Amount to withdraw in stMATIC. |
_referral | address | Referral address |
Returns:
Name | Type | Description |
---|---|---|
tokenId | uint256 | The token id |
delegate()
Delegate the deposited tokens into the StMatic contract between Lido's active operators. The tokens are delegated based on the operator's maxDelegationLimit factor.```solidity function delegate()
function delegate() external override
claimTokens()
Allows users to claim their tokens from the validators. This requires user to have an NFT that was minted during the requestWithdraw transaction.
function claimTokens(uint256 _tokenId) external override
Parameters
Name | Type | Description |
---|---|---|
_tokenId | uint256 | NFT Token ID of a pending withdrawal request. |
distributeRewards()
Distribute rewards accumulated by lido validators. 90% of rewards are buffered and redelegated. 10% is distributed between DAO(2.5%), insurance(2.5%), and active operators(5%).
function distributeRewards() external override
withdrawTotalDelegated()
Allows the NodeOperatorRegistry contract to claim the total amount delegated to a validator share.
function withdrawTotalDelegated(address _validatorShare) external
Parameters
Name | Type | Description |
---|---|---|
_validatorShare | address | Address of the validator share. |
rebalanceDelegatedTokens()
Rebalance the system by withdrawing from the validators that contains more token delegated to them and distributing the withdrawn tokens to validators with less.
function rebalanceDelegatedTokens() external override
calculatePendingBufferedTokens()
Calculate the total amount stored in all the NFTs owned by StMatic contract
function calculatePendingBufferedTokens()
public
view
returns (uint256 pendingBufferedTokens)
Returns:
Name | Type | Description |
---|---|---|
pendingBufferedTokens | uint256 | The total pending buffered tokens |
claimTokensFromValidatorToContract()
Claim and transfer the tokens from a specific validator share contract to the StMATIC contract. This requires a valid Lido NFT token.
function claimTokensFromValidatorToContract(uint256 _tokenId)
external
override
Parameters
Name | Type | Description |
---|---|---|
_tokenId | uint256 | Token ID of the claim request. |
DAO Methods
These methods can be called by DAO-only roles
setFees()
Set the DAO, operator, and insurance fee.
function setFees(uint8 _daoFee, uint8 _operatorsFee, uint8 _insuranceFee) onlyRole(DAO)
Parameters
Name | Type | Description |
---|---|---|
_daoFee | uint8 | DAO fee in %. |
_operatorsFee | uint8 | Operator fees in %. |
_insuranceFee | uint8 | Insurance fee in %. |
setDaoAddress()
Set a new DAO address
function setDaoAddress(address _address) onlyRole(DAO)
Parameters
Name | Type | Description |
---|---|---|
_address | address | Address of the DAO. |
setInsuranceAddress()
Set a new insurance address
function setInsuranceAddress(address _address) onlyRole(DAO)
Parameters
Name | Type | Description |
---|---|---|
_address | address | Address of the insurance. |
setNodeOperatorRegistryAddress()
Set a new node operator registry address
function setNodeOperatorRegistryAddress(address _address) onlyRole(DAO)
Parameters
Name | Type | Description |
---|---|---|
_address | address | Address of the insurance. |
setDelegationLowerBound()
Set a lower bound amount to delegate to a validator
function setDelegationLowerBound(uint256 _delegationLowerBound) onlyRole(DAO)
Parameters
Name | Type | Description |
---|---|---|
_delegationLowerBound | uint256 | Lower bound amount. |
setRewardDistributionLowerBound()
Set a lower bound for distributing reward to validators
function setRewardDistributionLowerBound(uint256 _rewardDistributionLowerBound) onlyRole(DAO)
Parameters
Name | Type | Description |
---|---|---|
_rewardDistributionLowerBound | uint256 | Lower bound reward amount. |
setPoLidoNFT()
Set PoLidoNFT address
function setPoLidoNFT(address _poLidoNFT) onlyRole(DAO)
Parameters
Name | Type | Description |
---|---|---|
_poLidoNFT | address | PoLido NFT address. |
setFxStateRootTunnel()
Set fxStateRootTunnel address
function setFxStateRootTunnel(address _fxStateRootTunnel) onlyRole(DAO)
Parameters
Name | Type | Description |
---|---|---|
_fxStateRootTunnel | address | FxStateRootTunnel address. |
setSubmitThreshold()
Set submit
threshold for users
function setSubmitThreshold(uint256 _submitThreshold) onlyRole(DAO)
Parameters
Name | Type | Description |
---|---|---|
_submitThreshold | uint256 | Threshold amount for submit. |
flipSubmitHandler()
Set the value of submit handler to false
function flipSubmitHandler() external override onlyRole(DAO)
setVersion()
Set contract version
function setVersion(string calldata _version) onlyRole(DEFAULT_ADMIN_ROLE)
Parameters
Name | Type | Description |
---|---|---|
_version | string | Version of the contract. |
Admin Methods
This method can be called by ADMIN-only roles
pasue()
Allows an authorized user with PAUSE ROLE
to pause the contract.
function pause() external onlyRole(PAUSE_ROLE);
unpasue()
Allows an authorized user with UNPAUSE ROLE
to unpause the contract.
function unpause() external onlyRole(PAUSE_ROLE);