A reference NFT Staking Program & Client for Solana NFTs

Overview

Solana NFT Staking

This is a reference NFT Staking Program & Client for Solana NFTs. This program is compatible with both Candy Machine v1 and Candy Machine v2 NFTs.


Disclaimer

Use at your own risk. I will not answer any support-related inquiries about this repository. If you have any issues or want any changes made, please make a fork or open a pull request.

This program was initially built during Solana v1.8.0. A closed source version is actively maintained and updated for Shadowy Super Coders. I will not be sharing those updates.

Yes, I do know this program does not use Metaplex's new "Collections" feature. No, I will not implement it in this open source repository. Feel free to open a PR with the changes if you'd like.


Support

If this repo helped you or your project in any way, any tips sent to A858S5BKJhrbc4mm8VcMMRWthBgtMu2AjDkAmrEKKEdD on Solana are highly appreciated.

Staking Setup + Commands

Reward token

  • NOTE: Only have to do this in development. In production, the reward token should already exist and you just have to transfer some into the vault later.

spl-token create-token --decimals 0

  • NOTE: Any decimal spl token will work. Just using 0 for development purposes.

spl-token create-account

  • NOTE: replace with the returned mint address from above

spl-token mint 1000000

Proof token

  • NOTE: This should be a 0 decimal token. Only mint the number based on however large your NFT collection is. You can mint more if needed, but it shouldn't be necessary.

spl-token create-token --decimals 0

spl-token create-account

spl-token mint 10000

Set admin, proof_mint and reward_mint variables in program/src/lib.rs

cd program && cargo build-bpf

  • NOTE: If cargo build-bpf doesn't work for you, run rm -rf ~/.cache/solana and then re-run the build command again. This should force solana to re-download and link the bpf utilities.

Deployment will cost about 3.31 sol

solana program deploy /path/to/nft-staking-v2/program/target/deploy/staking.so

Set reward_mint, proof_mint and program_id variables in client/src/main.rs

Run commands below in client directory

cargo build

Generate vault and transfer reward+proof tokens into the vault

cargo run -- generate_vault_address -e dev -s /path/to/deployer/id.json --min_period 60 --reward_period 10 --bonus_percentage 0 --bonus_period 30

  • NOTE: periods in seconds
  • NOTE: You can use decimals for reward period, min_period, bonus_percentage, and bonus_period. If you do use decimals, do extensive testing to make sure you get the expected amount in rewards and the timing is all correct.

spl-token transfer 1000000 --fund-recipient

  • NOTE: second address is the vault address returned from generate_vault_address cmd

spl-token transfer 10000 --fund-recipient

  • NOTE: second address is the vault address returned from generate_vault_address cmd

Add candy machine ID to whitelist

cargo run -- add_to_whitelist -e dev -s /path/to/deployer/id.json --reward 1 --maxreward 30 --candy_machine

  • is the first creator address on the NFTs in your collection. This should be a creator with 0% share.

Client commands

cargo run -- stake -e dev -s /path/to/deployer/id.json --nft

  • Stakes your NFT into the program vault, gives you a proof token back

cargo run -- stake_withdraw -e dev -s /path/to/deployer/id.json --nft

  • "Claims" your tokens on your nft without unstaking

cargo run -- unstake -e dev -s /path/to/deployer/id.json --nft

  • Unstakes your NFT and claims tokens at the same time

  • NOTE: Wait 60s before unstaking/claiming, as the min_period above is set to 60s. You can set this to 0 or 1 if you'd like users to instantly claim or unstake

cargo run -- withdraw -e dev -s /path/to/deployer/id.json --amount 10

  • NOTE: This is an admin-only command that lets you withdraw your reward tokens out of stake vault. This is a failsafe in case you need to kill this staking program and create a new one.
You might also like...
Terra liquid staking derivative

Terra liquid staking derivative. Of the community, by the community, for the community.

A re-write of polkadot staking miner using subxt to avoid hard dependency to each runtime version

Staking Miner v2 WARNING this library is under active development DO NOT USE IN PRODUCTION. The library is a re-write of polkadot staking miner using

Reference client for NEAR Protocol

Reference implementation of NEAR Protocol About NEAR NEAR's purpose is to enable community-driven innovation to benefit people around the world. To ac

Reference client for NEAR Protocol

Reference implementation of NEAR Protocol About NEAR NEAR's purpose is to enable community-driven innovation to benefit people around the world. To ac

Reference library that implements all the necessary functionality for developing a client that is compatible with TAPLE's DLT network.
Reference library that implements all the necessary functionality for developing a client that is compatible with TAPLE's DLT network.

⚠️ TAPLE is in early development and should not be used in production ⚠️ TAPLE Core TAPLE (pronounced T+ 🍎 ['tapəl]) stands for Tracking (Autonomous)

Demonstrates Solana data account versioning used in supporting the Solana Cookbook article: Account Data Versioning
Demonstrates Solana data account versioning used in supporting the Solana Cookbook article: Account Data Versioning

versioning-solana This repo demonstrates ONE rudimentary way to upgrade/migrate account data changes with solana program changes. What is data version

Eternally liquid. Forward compatible. Nested, conditional, & Multi-resourced NFTs.
Eternally liquid. Forward compatible. Nested, conditional, & Multi-resourced NFTs.

RMRK Substrate Rust Setup First, complete the basic Rust setup instructions. Run Use Rust's native cargo command to build and launch the template node

A specialized blockchain for testing use cases with the FRAME NFTs Pallet.

Substrate NFTs Node The Substrate NFTs node is a specialized blockchain for testing use cases with the FRAME NFTs Pallet. 🚀 The purpose of this node

The Solana Program Library (SPL) is a collection of on-chain programs targeting the Sealevel parallel runtime.

Solana Program Library The Solana Program Library (SPL) is a collection of on-chain programs targeting the Sealevel parallel runtime. These programs a

Comments
  • Error on cargo build-bpf

    Error on cargo build-bpf

    could not compile staking-nft-contract due to previous error,

    Seems to be from a linking issue: linking with \\?\C:\Users\myname\.local\share\solana\install\releases\stable-de065d865a08dea8eea289fd276423a720f8744c\solana-release\bin\sdk\bpf\dependencies\bpf-tools\llvm\bin\ld.lld failed: exit code: 1

    opened by hmount1 2
  • Stake_withdraw Collect Issue

    Stake_withdraw Collect Issue

    Hi, I set up everything and have been able to stake and collect my first staking reward. But I have been able to collect just the first one. I can't get any reward if I run the comment after once I collect the first reward.

    cargo run -- stake_withdraw -e dev -s KEYPAIR_PATH --nft NFT_TOKEN_ADDRESS

    Let's say every minute 30 Reward Coin. I should collect 30x60=1800 after 1 hour when I stake my NFT. But it doesn't work. Or don't know if my understanding is wrong.

    Thanks for your effort!

    opened by bilalcorbacioglu 1
  • client

    client

    cargo build on client directory return error: unexpected closing delimiter: } --> src/main.rs:345:5 | 66 | fn main() { | - this opening brace... ... 263 | }; | - ...matches this closing brace ... 345 | } | ^ unexpected closing delimiter

    error: could not compile staking-nft-tracy-client due to previous error

    opened by Matrix200086 0
Owner
Tracy Adams
I love solving problems that no one else has attempted. Web3 & Web2 Software Engineer
Tracy Adams
Solana NFT generative artwork program

resin Solana NFT generative artwork program Installation Depends on imagemagick for art generation, which can be installed here: https://imagemagick.o

null 4 Jun 24, 2022
NFT mixing program on solana chain

Mixture_machine Core logic of composing NFT Compose of NFT As you invoke compose_nft function with 2 or more child NFTs, child NFTs are locked in to M

Jay Soh 7 Dec 12, 2022
Galleries of NFTs using Solana and Rust for contracts

About this Package created to simplify the process of parsing NFTs on Solana. It consists of: Package basic things like fetch all NFTs for specific wa

Andrew Scott 1 Jan 28, 2022
Marinde Anchor-Based, first on mainnet, liquid-staking-program and mSOL->SOL swap pool

marinade-anchor Marinade-finance liquid staking program for the Solana blockchain Audits & Code Review Kudelski Security: https://marinade.finance/Kud

Marinade.Finance 42 Dec 11, 2022
My attempt at learning Solana program (smart contract) development through RareSkill's Solana course.

60-days-of-solana My attempt at learning Solana program (smart contract) development through RareSkill's Solana course. Originally, I was trying to cr

Jasper 3 Feb 25, 2024
Solana NFT marketplace boilerplate with anchor & react & candy-machine-cli

The Heros NFT Marketplace Boilerplate project is designed to let users fork, customize, and deploy their own nft marketplace app to a custom domain, ultra fast.

null 30 Dec 15, 2022
Solana NFT marketplace boilerplate with anchor & react & candy-machine-cli

Solana_Marketplace_HerosNFT The Heros NFT Marketplace Boilerplate project is designed to let users fork, customize, and deploy their own nft marketpla

null 30 Dec 15, 2022
A new, simple NFT standard for Solana

New Solana NFT Standard Current Issues The current NFT spec is pretty bad for a few reasons: every NFT requires multiple accounts (3+) the token accou

null 38 Oct 20, 2022
Here you'll find the open sourced code for the MOBIX staking contracts.

Mobix Staking Compile: rustup default stable cargo wasm Test: cargo test Optimize: quick and good: RUSTFLAGS='-C link-arg=-s' cargo wasm slow and b

MOBIX.ai 3 Apr 24, 2022
Yi Token by Crate Protocol: the primitive for auto-compounding single token staking pools.

yi Yi Token by Crate Protocol: the primitive for auto-compounding single token staking pools. About Yi is a Solana primitive for building single-sided

Crate Protocol 12 Apr 7, 2022