Andromeda
Ask or search…
K
Comment on page

NFT Staking

Introduction

The NFT Staking ADO is a smart contract that allows users to stake, unstake, and claim their NFT alongside an accrued reward after surpassing the unbonding period.
  • The unbonding period is set in seconds
  • The rewards are distributed per second. This means if the reward is 50 uandr, then after 10 seconds, my rewards should be 500 uandr.
  • 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,
pub kernel_address:String
}
{
"nft_contract":["andr1...","andr1...",...],
"unbonding_period": 100,
"reward":{
"denom": "uandr",
"amount": "50"
},
"kernel_address":"andr1..."
}
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.
kernel_address
String
Contract address of the kernel contract to be used for AMP messaging. Kernel contract address can be found in our deployed contracts.

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":"andr1...toeknid"
}
}
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":["andr1...","andr1...",...]
}
}
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": "andr1..."
}
}
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": "andr1..."
}
}
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":"andr1...tokenid"
}
}
Name
Type
Description
key
String
The key of the NFT to claim. Consists of concatenating the cw721 contract address + token Id.

AndrReceive

The rest of the executes can be found in the AndrReceive section.

QueryMsg

StakedNft

Queries information on a staked NFT.
Rust
JSON
pub enum QueryMsg {
#[returns(StakedNft)]
StakedNft {
key: String
}
}
{
"staked_nft":{
"key":"andr1...tokenid"
}
}
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":"andr1...",
"id":"3",
"contract_address":"andr1...",
"time_of_staking":"123437462",
"rewards":{
"denom":"uandr",
"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 {
#[returns(Vec<String>)]
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 {
#[returns(u64)]
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 {
#[returns(Coin)]
Reward {}
}
}
{
"reward":{}
}
Returns a type Coin with the amount and denom of the reward being distributed per second.

AndrQuery

A set of base queries common to all Andromeda ADOs. Check AndrQuery.