Git Product home page Git Product logo

synthetix-erc721-staking's Introduction

ERC721 Staking Smart Contract

Inspired by Synthetix's StakingRewards

Intro

To celebrate 100 Stars on my first Open Soruce NFT Staking Smart Contract I've chosen to come back to NFT Staking and solve some of the limitation my previous project has:

  1. There is no end of the period for the rewards distribution.
  2. The rewards are fixed and it's very expensive to modify them.

How it works

The onwer of the contract can set up a period of time for the rewards distribution and the amount of rewards to be distributed. The rewards are distributed to the stakers based on the amount of NFTs they have staked and the amount of time they have staked them, so the APY is dynamic and depends on how many NFTs are staked at a given time.

If you want to know more about how the contract works from a technical perspective and understand the math behind it, you can view SmartContractProgrammer's video series on the subject.

How to use

Owner:

  1. You will need to already have a NFT Collection deployed and a Reward Token deployed. You can find templates for both of them on some of my other projects:
    1. ERC721 NFT Collection
    2. ERC20 Token
  2. Deploy the contract and set the NFT Collection address and the Reward Token address.
  3. Send the amount of Reward Tokens you want to distribute to the contract.
  4. Set the rewards distribution period and the amount of rewards to be distributed.
  5. After the current period ends, you can set a new period and amount of rewards to be distributed.

Stakers:

  1. Approve the contract to transfer your NFTs.
  2. Stake your NFTs by calling the stake function.
  3. See your staked NFT Token IDs and accrued rewards by calling the userStakeInfo function.
  4. Call the claimRewards function to receive your rewards.
  5. Call the withdraw function to unstake specific NFTs or the withdrawAll function to unstake all your NFTs and claim your rewards in one transaction.

If this was helpful please consider donating: 0xA4Ad17ef801Fa4bD44b758E5Ae8B2169f59B666F. Every bit helps me keep working on Open Source projects, and if you have any recommendations or suggestions for future projects, please let me know!

Setup

Install dependencies

yarn

Change the .env.example file name to .env and populate it following the instructions:

# Optional for deploying and interacting with contracts using a private key:
PRIVATE_KEY=
# Optional Etherscan key, for verification of the contracts on Etherscan:
ETHERSCAN_API_KEY=
# Optionals RPC-URLs for interacting with Ethereum Mainnet and Goerli:
ETH_MAINNET_URL=
ETH_GOERLI_URL=
# Bool: optional for gas reports generated when running tests:
REPORT_GAS=

Compile contracts


yarn hardhat compile

Test


yarn hardhat test

Deployment

Available networks

  • Sepolia: --network sepolia
  • Ethereum Mainnet: --network main

Set a fixed gas price

To set a fixed gas price edit the hardhat.config.ts file, adding a gas price for the wanted network. See the example below:

const NETWORK_GAS_PRICE: Partial<Record<string, number>> = {
    mainnet: ethers.utils.parseUnits("20", "gwei").toNumber(),
    // "sepolia": ethers.utils.parseUnits("10", "gwei").toNumber(),
};

Deploy Staking Contract

yarn hardhat deploy --nft <NFT_COLLECTION_ADDRESS> --token <REWARD_TOKEN_ADDRESS> --network <NETWORK>

Verification on Etherscan

If you also want to verify you contract, add the flag --verify in the deploy command like so:

yarn hardhat deploy --verify --nft <NFT_COLLECTION_ADDRESS> --token <REWARD_TOKEN_ADDRESS> --network <NETWORK>

synthetix-erc721-staking's People

Contributors

andreitoma8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.