Vesting and Staking App
In this example, we will be building a simple yet effective vesting application.
Defining our App
The App is built on the Andromeda Chain.
The build is done on testnet using the Beta ADOs. However, these ADOs may be outside of beta by the time you’re reading this.
For this build, let us assume the following:
A web-3 project is launching their own native token.
Employees of this company get an certain amount of tokens that will be vested for 1 year.
When the vested tokens are claimed, they are automatically staked.
The company will be building the Apps for its employees.
Defining the Components
Vesting component to vest the native tokens.
Staking component to stake the tokens once released from vesting.
Building the App
We will be creating the App for one employee. Each employee would need a separate App for them which can be built the same way we are doing this one.
Open a new empty project in the ADO Builder and give the app an appropriate name:
Vesting Component
First component we will add is the Vesting ADO:
Here we have to specify two fields:
Denom: The micro denomination of the token that will be staked. In our case, we will be using the Andromeda chain/token, so we can specify "uandr".
The Recipient: The address or ADO who will receive the tokens once vesting is complete. In our case, we want the tokens to go to the staking ADO whenever they are claimed from vesting, so we need to reference it. We can do that by using "./" followed by the component name for the staking ADO.
By default, the staking ADO will have the name "validator-staking-1". If you decide to change this default name, make sure you use the correct reference here.
So far, we have instructed the vesting ADO to release the vested tokens to the staking ADO. When the these tokens are sent, we want them to be automatically staked. To do so, we will have to attach a message along with the recipient.
To do this, we select "Option 1" for the message and we specify the staking message of the Staking ADO. From the docs we can see that the message is the following:
The message needs to be attached as base64. The web-app supports using JSON format that will be auto converted for us. Select JSON instead of base64 and paste the below JSON message into the text box:
You can find validator addresses in our testnet explorer.
The vesting component is now configured and we can move on to the staking component.
Staking Component
Add the Validator Staking ADO.
The default validator address defines the address to be used in case we call a staking message without a specified validator. We can use the same validator address used in our attached message.
We could have opted to not specify the validator in our attached message earlier as the staking ADO will use the default validator which is the same in our case.
Now the App is ready, go ahead and publish.
Setting Up the App
Creating the Vesting Batch
First thing we will do, is create the vesting batch for the employee which contains the amount of tokens to be vested and the vesting schedule to use.
Select the "Create Batch" message for the Vesting component:
This will open up the a panel where we can configure the vesting schedules:
Here we specified the following:
Lockup Duration: Amount of time where the tokens are completely locked and vesting is yet to start.
Release Amount: Amount of tokens to be released every release interval. We can use a fixed amount of tokens, or a percentage of the total amount. In this example, 5% is specified.
Release Interval: Amount of time between every release. Releases start after the lockup duration has ended. 10 min is specified here.
This means that once we publish this message, the tokens will be locked for 1 hour. Then every 10 min, 5% of the tokens will be released and can be claimed by the contract owner.
Before we publish, we need to provide the tokens that will be vested. To do so, we attach funds to the message by selecting "Add Attachment", then "Add Fund":
Here we attach 10 ANDR tokens. Now we can publish.
Transferring Ownership
The App is now set up. After 1 hour, the tokens will start to vest and will be released every 10 min to claim. When claimed, they will go to the defined recipient, who in our case is the Staking ADO and will be automatically staked for us.
Now as the company, we have successfully created the App. Both the Vesting and Staking ADOs (You can read more in docs) are set up in a way where the contract owner has all the controll over them. For example, only the contract owner is able claim tokens from the Vesting ADO, and any claimed rewards/unstaked tokens from the Staking ADO will go to the contract owner. This means that we need to transfer ownership of this App, or at least the components, to the employee we have set this up for.
You can find the steps for ownership transfer in our ADO Ownership section.
Checking the Results
Once the lockup period has passed, and one release interval has been reached, we can claim some tokens from vesting and check the status of our staking ADO.
If you have transferred ownership, you will need to perform these messagses using the new owner.
From the list of modifiers for the vesting component, select the "Claim All" message. This will allow you to claim any tokens that have finished vesting:
You dont need to specify anything here and can just publish. Next, let us check if the tokens have been staked. From the list of queries for the staking ADO, select "Staked Tokens":
Then lets query our staked tokens:
By not specifying the Validator Address, the default validator will be taken.
As we can see, there are 500000uandr tokens staked which is equal to 0.5 ANDR, 5% of the 10 ANDR vested. Since we just claimed one release from the vesting, and each release is 5%, then the staked amount is correct. Now every time new tokens are done vesting, we can claim them and have them be automatically staked as we have seen.
Finally, we can claim the rewards from staking by simply calling the "Claim" message from the staking components:
Once published, any rewards from staking will be sent to your address.
Last updated