Giter Club home page Giter Club logo

badgerdao's Introduction

Badger Rescue Faucet

This is a gamified faucet designed for qualifying members of the badger community that have found themselves stranded on Binance Smart Chain without any BNB to operate with. This happens when users use bridges (like Binance Bridge), but forego/forget acquiring BNB gas funds. Trying to get enough BNB at this point, just to finalize one or two more transactions, can be costly and stressful. So why not try to relax a bit and play a little game? You may earn BNB rewards for a good score, and you can finalize your Binance Smart Chain adventure, without it costing you extra.

BSC Testnet Demo

Demo

Playable: http://kraniumtivity.com/Extra/RescueFaucet

Full Gameplay: https://youtu.be/VAFihQhIPsw

Faucet Contract: 0x3057ae5dda530e2887fe50b30382A13f2aE72FEe (source)

Summary

The Badger Rescue Faucet (BRF) is a mini-game that grants BNB to players who are whitelisted for use. Players must try catching coins falling from the clouds before time runs out, all while running across the edge of a cliff without falling off. Successful badgers will claim token amounts based on their performance. Unfortunate badgers will forfeit any collected coins. The coins represent a configurable amount of BNB granted to the players wallet upon winning.

Win Lose
Win Lose

Technical Overview

Whitelisting/Validation

To qualify for faucet use, badgers must own at least 10 Wei of bBadger on both Ethereum & Binance Smart Chain testnets. You can run the minting brownie script to grant yourself enough tokens.
You can view the validators here & here

Deployment Layout

Alt text here
The way to run validation/gate-keeping is via the game application itself, since it is network agnostic. The validation happens on-chain with TokenHolderThresholdValidator contracts. BSC contracts can't directly call Ethereum contracts, so we have the game independently call each network's contracts. It expects both validators to succeed before letting you actually play the game. These validators simply check if you have enough of a particular token to qualify for the faucet (aka, you meet the threshold of tokens held). At first, the game will prevent you from playing, because you need the qualifying token, which in this case is the BrownieWrap_Token (representative of bBadger). In the future, these validators can incorporate BadgerTree.

Token Grant Calculation

You can specify the maximum payout amount when creating the smart contract instance on the blockchain. In the current BLF template, the game design has a variable score and total where score <= total. The difference between score and total form the ratio that is factored into the max payout:

FinalPayout = (Score/Total) * MaxPayout

Due to how fixed point math works in EVM, the actual implementation in Solidity is refactored.

Game To Smart Contract Config

Once the smart contract has been manually deployed, the game must be built with the updated smart contract info:

  1. Mainnet/Testnet infura API address.
  2. Faucet smart contract address.
  3. Designated gas wallet address to cover expenses.
  4. Designated gas wallet private key to sign faucet grant transactions.

Needless to say, don't save the production private key into the project. You should only enter it manually prior to building the WebGL project.

Limitations / Pending Improvements

Game only runs on Chrome

I'm not exactly a web dev so I had to rely on miscelaneous tutorials to get the WebGL properly bootstrapped with Web3 plugins such as Metamask. Brave Browser doesn't work, for example. The Metamask button on the start screen has only worked when running on Chrome with Metamask being the sole Web3 provider installed. More details on this issue to come.

Instant Replay Vulnerability

After playing a session (win or lose), the player can bypass the retry delay period simply by reloading the page immediately. A user could do this consecutively to illegitimately boost their rewards, potentially draining the faucet. This happens because time tracking for each player is done via block timestamps in Solidity. The delay period for any player is only updated on the next block. The solution here is to either:

  • Query the mempool to validate whether a player has pending payouts (including zero amounts).
  • Centralize the deployment by saving some of the game session data on a persistent backend, possibly even the website's own database.

Overdraft grant transaction failure

There may be multiple players interacting with the faucet simultaneously. Because we only check for balance before starting a game, the faucet may become depleted by another player's payout before your game ends. When requesting your payout, the transaction will fail because there is not enough balance remaining. Similar to above, the solution here is to either:

  • Query the mempool for pending payouts and pre-calculate the maximum collective payout to determine if there is enough for a 100% payout game session.
  • Centralize the deployment by saving some of the game session data on a persistent backend, possibly even the website's own database.

Accepting pull requests!

logo badgers never hide

badgerdao's People

Contributors

kilogold avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.