Git Product home page Git Product logo

no-loss-erc721-raffle's Introduction

No-Loss NFT Raffle

No-loss NFT raffle that deposits user funds into a yield-bearing strategy and forwards all interest to NFT creator.

Background

Traditional auctions & raffles require users to deposit money that is not returned to them. Premium Bond inspired mechanisms (such as PoolTogether) allow users to participate in a lottery with the ability to redeem their original deposit, regardless of whether they win. The NFTRaffle.sol contract in this repo contains similar logic for NFTs. An NFT creator is able to raffle off their NFT, collecting the interest generated from depositor's tokens during the raffle period. Chainlink's VRF mechanism is leveraged to fairly determine a user at random (weighted by the size of their deposit).

image

Traditional auctions & raffles require users to deposit money that is not returned to them. Premium Bond inspired mechanisms (such as PoolTogether) allow users to participate in a lottery with the ability to redeem their original deposit, regardless of whether they win. The NFTRaffle.sol contract in this repo contains similar logic for NFTs. An NFT creator is able to raffle off their NFT, collecting the interest generated from depositor's tokens during the raffle period. Chainlink's VRF mechanism is leveraged to fairly determine a user at random (weighted by the size of their deposit).

Flow for an NFT Raffler

  • Acquires a Chainlink VRF Subscription Account and funds it with LINK token (see Chainlink docs here
  • Configures settings and deploys contract, adding the deployed contract address as a authorized Chainlink Consumer to the subscription account created above
  • Escrows the NFT in the contract via depositNFT
  • After the user deposit period is over, calls investRaffleDeposits to invest raffle deposits into a yield-bearing strategy (currently Yearn)
  • After the interest generation period is over, calls withdrawRaffleDepositsFromYearn to withdraw the original yearn deposit along with interest. The interest generated is automatically transferred to the owner.

Flow for a user

  • Calls enterRaffle with a specified amount of tokens to enter the raffle
  • After the interest generation period is over, anyone can invoke requestRandomWords, which will trigger the chainlink VRF process to kick off
  • The Chainlink VRF coordinator will invoke the fulfillRandomWords callback, which will randomly assign a winner
  • All users can withdraw their original deposit via withdrawRaffleDeposit
  • The winner can claim the NFT via claimWinner

Build & Testing

This repo uses Foundry for both the build and testing flows. Run forge build to build the repo and forge test for tests.

Improvements

This contract assumes that the interst-bearing strategy will return a positive interest, which is not always the case. A future iteration can be made more robust to account for a loss of funds and handle business logic accordingly. This contract is a prototype, and has not been gas-optimized either.

Acknowledgements

Part of this idea was inspired by PoolTogether and they work they have done with their no-loss loterry.

Disclaimer

This was a minimal implementation created for personal uses and for fun, and should not be used in production.

no-loss-erc721-raffle's People

Contributors

verumlotus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.