Giter Club home page Giter Club logo

nonfungiblefarm's Introduction

NonFungibleFarm

Farm ERC-1155 NFT by staking ERC-20 LP Tokens

Video Explanation: https://youtu.be/vIcf74CvsCs

User Flow:

  • NFT's are deposited into this contract, having some Price as points associated to them.
  • In order to claim an NFT, the user must have sufficient points to reach Price threshold.
  • To increase points balance, user must deposit lp tokens to this contract.
  • points balance increases dynamically with each passing second allowing user to Farm NFTs!

Features:

  • Supports ERC-1155 NFT
  • Stake LP tokens.
  • Rate of NFT accumulation proportional to amount of LP tokens user is providing.
  • Farm for all NFTs at once. Choose particular NFTs on claim.
  • Resume farming from where left, if LP tokens withdrawn in between.
  • Claim all eligible random NFTs with farmed points balance.
  • Withdraw LP tokens, and claim NFTs in single transaction.

Functions:

constructor(uint256 _emissionRate, IERC20 _lpToken) public

_emissionRate: points generated per LP token (wei) per second staked by user

_lpToken: token address to be staked

function addNFT(
        address contractAddress,    // token contract address. Only ERC-1155 NFT Supported!
        uint256 id,                 // token id
        uint256 total,              // amount of NFTs deposited to farm (need to approve before)
        uint256 price               // price in `points`
    ) external;

Can only be called by owner. To add ERC-1155 NFT to be farmed by others. Owner must have approved contract to transfer NFT before calling this function.

function deposit(uint256 _amount) external;

Called by user to stake _amount of LP tokens in the contract. User must have approved contract to spend at least _amount of LP tokens.

function pointsBalance(address userAddress) public view returns (uint256) 

Dynamic function to get points balance accumulated till now.

function claim(uint256 _nftIndex, uint256 _quantity) public;

Allow user to claim _quantity of NFT at index _nftIndex in nftInfo array, if sufficient points accumulated (else transaction reverts). NFTs are farmed and sent to user address.

function claimRandom() public;

Allow user to claim random NFTs from the NFT pool until they exhaust their point balance.

function withdraw(uint256 _amount) public;

Allow user to withdraw _amount of LP tokens. Reverts if _amount exceeds deposited LP tokens by user.

function exit() external;

Allow user to claim random NFTs and withdraw all LP tokens from contract.


Local Project Set Up:

  1. Install Required packages. npm i

  2. Compile contracts truffle compile

  3. Run tests. Run these commands parallelly, one after another: ganache-cli npm run tests

nonfungiblefarm's People

Contributors

apoorvlathey 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.