Liquid staking Dapps

Overview

With the adoption of IIP13, that allows representing IoTeX staking buckets as Non-fungible Tokens (NFTs), liquid staking solutions that rely on smart contracts to manage their stakes via system-level smart contracts can now be developed on IoTeX.

-> Visit the original IIP-13 Proposal

Read more

Staking in the IoTeX blockchain was originally implemented as part of the protocol, which prevents direct interaction of smart contracts with staking functionalities. While IIP12 addressed the the possibility of accessing the full staking protocol from the Ethereum JSON API by means of a virtual contract, that one is not an actual EVM smart contract, and thus it is not visible and cannot be called by other smart contracts.

In this section we will highlight the details of how Staking as NFT works and provide documentation on how to engage with staking buckets to offer liquid staking solutions on IoTeX.

How it works

Liquid Staking has been enabled with the implementation of a so called "System Staking Contract". This is the primary contract responsible for providing the functionalities laid out in IIP-13. It manages tasks such as creating, modifying, transferring, and querying staking Buckets and their associated NFT tokens.

Visit the original IIP-13 Proposal ->

The System Staking Contract

Source Code | ABI

Network
Address

Testnet

0x52ab0fe2c3a94644de0888a3ba9ea1443672e61f

Mainnet

0x68db92a6a78a39dcaff1745da9e89e230ef49d3d

Bucket Types

In the context of staking as NFT, a "Bucket Type" represent a specific staking configuration, including the deposit amount, the preset lock duration, and the status of the StakeLock option. Currently, three bucket types are supported in the implementation, that are listed below:

Amount (IOTX)
Duration (Days)
Duration (Blocks)
StakeLock

10,000

91

1,572,480

ON by default

100,000

91

1,572,480

ON by default

1,000,000

91

1,572,480

ON by default

Examples

In this section we explore in details how to interact with the SystemStaking contract from another contract to enable liquid staking functionalities.

Setting up the Environment

  1. When developing your Liquid Staking contract, ensure you include the ISystemStaking contract interface from the IIP13 repository.

  2. Ensure your client contract implements IERC721Receiver, as it will receive the NFT Bucket from the SystemStaking contract upon staking creation.

Staking IOTX from your Contract

The SystemStaking contract provides three stake functions that enable the creation of a new staking bucket in different scenarios. Each of them returns the id assigned to the newly created bucket, which coincides with the NFT token id:

For instance, to generate a new NFT bucket with a 100 IOTX deposit, assigned to an eligible IoTeX delegate, you would use:

Note on Staking Amount and Duration

When creating a new staking bucket, it's important to ensure that the chosen stake amount and duration match one of the combinations the SystemStaking contract supports, otherwise the action will revert. These combinations are called "Bucket Types". For the best user experience, consider fetching the list of all supported bucket types from your dApp frontend to guide users during the staking process.

To obtain the current list of bucket types, use the following methods from the SystemStaking contract:

Copy

Note on Delegate Owner Addresses

When creating a new staking bucket or changing the delegate of an existing bucket, it's important to input the delegate's "owner address," also referred to as the delegate's "profile address." This address uniquely identifies each IoTeX delegate. Ensure that the addresses you utilize actually belong to delegates and that they are eligible (meaning their self-stake amount is at least 1.2M IOTX). Failing to do so will cause a contract action revert.

To facilitate this process in your frontend, leverage the IoTeX Staking virtual contract to access details regarding delegate names, addresses, and self-staking data. The relevant method is listed below, but for comprehensive details, please refer to the IoTeX Staking Integration section ->

Changing the StakeLock status

When a new staking bucket is created using the SystemStaking contract, the StakeLock option is enabled by default. In this state, the bucket remains locked for its designated lock duration, and this duration does not decrease over time. While the activated StakeLock option ensures higher rewards, if you plan to unstake a bucket at a specific time, you must deactivate the StakeLock option for that bucket well in advance, specifically the same number of days as the lock duration.

Unstaking a bucket

Before you can withdraw the IOTX deposit, unstaking a bucket is a prerequisite. For a bucket to qualify for unstaking, it must be in the "unlocked" status. This indicates that the StakeLock option for that specific bucket must have remained deactivated throughout the entire lock duration of the bucket. Once initiated, the unstaking process lasts 3 days (equivalent to 51,840 IoTeX blocks). During this period, the bucket remains locked, does not generate staking rewards, and is immune to any operations.

Withdrawing a bucket

Before you can withdraw a deposit, it must have completed the unstaking process.

More operations

Conclusion

These are the foundational steps for interacting with IIP-13 contracts, that allows the creation of Liquid Staking solutions. Liquid staking allows users to access the benefits of staking in a blockchain network while still maintaining liquidity and flexibility over their staked assets, which create a more attractive and versatile staking experience.

For more advanced operations and deeper insights, please refer to

→ IIP-13 proposal -> Contract's source code.