Andromeda
Search…
NFT Staking

Introduction

The CW721 Staking ADO is a smart contract that allows users stake, unstake, and claim their NFT alongside an accrued reward after surpassing the unbonding period.
Note:
  • The unbonding period is set in seconds
  • The rewards are distributed per second. This means if the reward is 50 ujunox, then after 10 seconds, my rewards should be 500 ujunox.
  • When the NFT is staked, it is assigned a unique key, which consists of concatenating the cw721 contract address + token Id.
Ado_type: nft-staking

InstantiateMsg

Rust
JSON
pub struct InstantiateMsg {
pub nft_contract: Vec<String>,
pub unbonding_period: u64,
pub reward: Coin,
}
{
"nft_contract":["juno1...","juno1...",...],
"unbonding_period": 100,
"reward":{
"denom": "ujunox",
"amount": "50"
}
}
Name
Type
Description
nft_contract
Vec<String>
The contract addresses of the NFT contracts that can stake their NFTs using this contract.
unbonding_period
u64
The unbonding period (time to unstake) of the NFTs in seconds.
reward
Coin
The rewards to be distributed per second.

ExecuteMsg

ReceiveNft

Receives an NFT from one of the nft_contract set on instantiation by executing a SendNft from the NFT contract with the attached Stake message
pub enum ExecuteMsg {
ReceiveNft(Cw721ReceiveMsg),
}

Cw721ReceiveMsg

pub struct Cw721ReceiveMsg {
pub sender: String,
pub token_id: String,
pub msg: Binary,
}
Here the message should be a Cw721HookMsg of type Stake which tells the contract to stake the NFT.
pub enum Cw721HookMsg {
Stake {},
}

Unstake

Unstakes the NFT with the specified key.
Only available to the token owner.
The minimum time to call unstake after staking is one day.
Rust
JSON
pub enum ExecuteMsg{
Unstake {
key: String,
}
}
{
"unstake":{
"key":"juno1...4"
}
}
Name
Type
Description
key
String
The key of the NFT to unstake. Consists of concatenating the cw721 contract address + token Id.

UpdateAllowedContracts

Updates the list of allowed NFT contracts to stake using this ADO.
Only available to the contract owner/operator.
The old list is overwritten by the new one.
Rust
JSON
pub enum ExecuteMsg {
UpdateAllowedContracts {
contracts: Vec<String>,
}
}
{
"update_allowed_contracts": {
"contracts":["juno1...","juno1...",...]
}
}
Name
Type
Description
contracts
Vec<String>
The new list of contract addresses.

AddAllowedContract

Add a new NFT contract to the list.
Only available to the contract owner/operator.
Rust
JSON
pub enum ExecuteMsg {
AddAllowedContract {
new_contract: String,
}
}
{
"add_allowed_contract":{
"new_contract": "juno1..."
}
}
Name
Type
Description
new_contract
String
The contract address of the NFT contract to add.

RemoveAllowedContract

Remove a new NFT contract to the list.
Only available to the contract owner/operator.
Rust
JSON
pub enum ExecuteMsg {
RemoveAllowedContract {
old_contract: String,
}
}
{
"remove_allowed_contract":{
"old_contract": "juno1..."
}
}
Name
Type
Description
old_contract
String
The contract address of the NFT contract to remove.

UpdateUnbondingPeriod

Changes the unbonding period to a new one.
Only available to the contract owner/operator.
Rust
JSON
pub enum ExecuteMsg {
UpdateUnbondingPeriod {
new_period: u64,
}
}
{
"update_unbonding_period":{
"new_period": 1000
}
}
Name
Type
Description
new_period
u64
The new unbonding period in seconds.

Claim

Sends back the NFT to its original owner alongside the accrued rewards.
Can be executed after the unbonding period has passed.
Rust
JSON
pub enum ExecuteMsg {
Claim {
key: String,
}
}
{
"claim":{
"key":"juno1...2"
}
}
Name
Type
Description
key
String
The key of the NFT to claim. Consists of concatenating the cw721 contract address + token Id.

AndrReceive

QueryMsg

StakedNft

Queries information on a staked NFT.
Rust
JSON
pub enum QueryMsg {
StakedNft {
key: String
}
}
{
"staked_nft":{
"key":"juno1...3"
}
}
Name
Type
Description
key
String
The key of the NFT get info on. Consists of concatenating the cw721 contract address + token Id.

StakedNft

Rust
JSON
pub struct StakedNft {
pub owner: String,
pub id: String,
pub contract_address: String,
pub time_of_staking: Timestamp,
pub time_of_unbonding: Option<Timestamp>,
pub reward: Coin,
pub accrued_reward: Option<Coin>,
}
{
"owner":"juno1...",
"id":"3",
"contract_address":"juno1...",
"time_of_staking":"123437462",
"rewards":{
"denom":"ujunox",
"amount":"50"
}
}
Name
Type
Description
owner
String
The owner of the token.
id
String
The token id.
contract_address
String
The NFT contract address.
time_of_staking
Timestamp
The time of staking. Epoch time in seconds.
time_of_unbonding
Option<Timestamp>
Optional time of unbonding if the NFT has been unstaked.
rewards
Coin
The rewards being distributed per second.
accrued_reward
Option<Coin>
The amount of rewards accumulated from staking.

AllowedContracts

Queries the list of allowed NFT contracts to stake using this contract.
Rust
JSON
pub enum QueryMsg {
AllowedContracts {}
}
}
{
"allowed_contracts":{}
}
Returns a Vec<String> containing the addresses of the NFT contracts allowed to send NFTs to stake.

UnbondingPeriod

Queries the unbonding period.
Rust
JSON
pub enum QueryMsg {
UnbondingPeriod {}
}
}
{
"unbonding_period":{}
}
Returns a u64 value which represents the unbonding time in seconds.

Reward

Queries the reward being distributed for staking.
Rust
JSON
pub enum QueryMsg {
Reward {}
}
}
{
"reward":{}
}
Returns a type Coin with the amount and denom of the reward being distributed per second.

AndrQuery

Check AndrQuery.
Copy link
Outline
Introduction
InstantiateMsg
ExecuteMsg
ReceiveNft
Unstake
UpdateAllowedContracts
AddAllowedContract
RemoveAllowedContract
UpdateUnbondingPeriod
Claim
AndrReceive
QueryMsg
StakedNft
AllowedContracts
UnbondingPeriod
Reward
AndrQuery