Code Monkey home page Code Monkey logo

nitroshibaduel's Introduction

NitroShibaDuel

A simple on-chain game for holders of any Nitro Shiba NFT collection.

WARNING: NOT YET READY FOR PRODUCTION, STILL IN DEVELOPMENT

Features

  • Bet $NISHIB and/or your NFT
  • Participate in community Jackpot rounds
  • Win or lose it all in Double Or Nothing mode
  • Rounds are not limited to two players
  • MEV-resistant randomness
  • No administrative withdraw function so contract is rug-proof
  • Code is heavily commented to help anyone independently review it

Modes

  • 1) SimpleBet
    • Each NFT holder places matching bets and the winner takes the pot
    • This is the only mode that can convert to DoubleOrNothing mode
  • 2) DoubleOrNothing
    • A two-player SimpleBet Duel can be converted into DoubleOrNothing
    • Must be toggled by both players before the SimpleBet winner withdraws
    • If SimpleBet has more than two players, DoubleOrNothing cannot be enabled
  • 3) PVP
    • Each NFT holder bets one of their NFTs against each other
    • Winner takes all
  • 4) PVPPlus
    • PVP but with a token bet as well
    • Basically SimpleBet + PVP
  • 5) Jackpot
    • Any NFT holder can trigger a jackpot round that lasts as long as the jackpotExpiry value
    • Only one jackpot can be running at any given time
    • Jackpot initiator can set the jackpot bet as long as it is within bet minimum and maximum thresholds

FAQ

What administrative functions are present?

The admin can perform the following actions:

    function changeMinimumBet_(uint256 _minimumBet) public onlyOwner {
        minimumBet = _minimumBet;
    }

    function changeMaximumBet_(uint256 _maximumBet) public onlyOwner {
        maximumBet = _maximumBet;
    }
    
    function changeDuelExpiry_(uint256 _duelExpiry) public onlyOwner {
        duelExpiry = _duelExpiry;
    }

    function changeJackpotExpiry_(uint256 _jackpotExpiry) public onlyOwner {
        jackpotExpiry = _jackpotExpiry;
    }

    function cancelJackpot_(uint256 _jackpotIndex) public onlyOwner {
        _cancelDuel(_jackpotIndex);
    }

What is the reasoning behind these administrative functions?

changeMinimumBet_(uint256 _minimumBet)
changeMaximumBet_(uint256 _maximumBet)

- These functions allow the contract owner to adjust the minimum and maximum bet thresholds
- The primary purpose is that a minumum bet needs to be enforced to prevent transaction spam
- The maximum bet prevents jackpot rounds from being initialized with too high a bet for all participants
    - Jackpots have an independent expiry and are only cancelable by admin
- If the price of $NISHIB fluctuates wildly, limits will need to be adjusted

changeDuelExpiry_(uint256 _duelExpiry)
changeJackpotExpiry_(uint256 _jackpotExpiry)

- These functions allow the contract owner to adjust duel and jackpot expiries
- Duel expiry prevents MEV by not allowing bots to withdraw their bids before they can calculate vrfOutputs
- Jackpot expiry is enforced by preventing anyone from executing it prematurely
- The community may want these values adjusted over time, so the admin reserves the right to do so here

cancelJackpot_(uint256 _jackpotIndex)

- Only the owner can cancel a Jackpot duel
- Prevents jackpot initiators from trolling by canceling Jackpots
- Contract owner is prevented from canceling if they participated in the jackpot

Usage

function initiateDuel(
    uint256 _tokenId,
    uint256 _bet,
    Mode _mode
) public returns (uint256 _duelID) { ... }
  • 1) Initiate Duel
    • This function is called to start a duel
    • Duel Mode is determined by _mode parameter
    • Returns the duelID for the interface

function joinDuel(uint256 _tokenId, uint256 _duelID) public { ... }
  • 2a) Join Duel
    • This function processes all of the logic required to join an open duel, regardless of mode
    • All participants calling join must own NFT at _tokenId

function cancelDuel(uint256 _duelID) public { ... }
  • 2b) Cancel Duel
    • Before a duel is executed, the initiator can cancel it
    • Cancelation processes asset (token and/or NFT) refunds for all participants (if any)
    • Must be run prior to duel execution

function executeDuel(uint256 _duelID) public returns (address winner) { ... }
  • 3) Execute Duel
    • Allow only duel participants to execute duel
    • As long as enough duel participants have joined, execution can occur
    • Jackpot execution only occurs after the jackpot deadline
    • Returns winner address for the interface

function doubleOrNothingDuel(uint256 _duelID, uint256 _tokenId) public { ... }
  • 4) Enable DoubleOrNothing Mode (optional)
    • Allows participants in a two-party SimpleBet to enable DoubleOrNothing mode
    • Only two participants is a hard requirement
    • Both parties must call this before executeDuel() can be called again

function withdrawDuel(uint256 _duelID) public returns (bool success) { ... }
  • 5) Withdraw Duel Pot
    • Allows winner to withdraw duel pot
    • Once withdrawal has occurred, DoubleOrNothing mode cannot be enabled

Installation

NitroShibaDuel was made with foundry, and thus can be installed as follows:

git clone https://github.com/Zodomo/NitroShibaDuel

cd NitroShibaDuel

forge install

forge build

forge test

Authors

Acknowledgements

nitroshibaduel's People

Contributors

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