Git Product home page Git Product logo

blast-gas-king's Introduction

Gas King of the Hill - A Blast of a Game

Burn gas for points, claim everyone's refund. Wait longer to claim more. Live on Blast testnet at https://blastgasking.xyz/.

Quick Game Rules

Earn points and become the King of the Hill by burning gas. The game is played in rounds on various Hills.

The King can claim a refund for all gas burned during the round after a certain delay (claimDelay). Keep earning points during this time to maintain your lead. If someone else takes the lead, the wait time resets.

According to Blast's rules refunds grow over time, from 50% to 100%.

Player Strategies:

  • First Player: If no one challenges you, wait until 100% refund to get all your fees back.
  • Second Player: Overtake the leader and you're guaranteed to earn more than what you spent, thanks to a minimum 50% fee claim.
  • Beyond Two Players: More competition means profit for the winner is guaranteed.

Contracts flow

  1. GasKingGame contract is used to create Hills (game servers) which differ only by claimDelay. There's 3 default hills (1 minutes, 1 hour, 1 day).
  2. The Hill is where the game is played. Each player competes for points by burning gas via burnForPoints.
  3. The player with the most points can claim all the contract's (Hill's) gas fees using claimWinnings if they have been "king" longer than claimDelay.
  4. After a successful claim, a new round of the game starts.
  5. Historical data is saved for previous plays and accessible via getRound.
  6. Claimable amount off-chain is accessible via claimableSimulate.

Deployments

  1. GasKingGame (w. 3 default hills): https://blastscan.io/address/0x0958f342bd16c243e500ebb20ec7593e19e77245#code. First Hill: https://blastscan.io/address/0x5e1038026368279e95179d693716c6bda6fdd25e#code.
  1. GasKingGame (w. 3 default hills): https://testnet.blastscan.io/address/0x0958f342bd16c243e500Ebb20ec7593e19e77245. First Hill: https://testnet.blastscan.io/address/0x5E1038026368279E95179D693716c6BDA6FDd25e.

Interfaces:

interface GasKingGame {
  // mutative
  function createHill(uint claimDelay) external returns (address hill);

  // views
  function hillAddresses(uint) external view returns (address);
  function lastHillIndex() external view returns (uint);

  event HillCreated(uint claimDelay, address hill);
}

interface Hill {
  // mutative
  function burnForPoints() external;
  function claimWinnings() external returns (uint amount);
  receive() external payable;

  // mutative but should be used as view (via simulation)
  function claimableSimulate() external returns (uint claimable);

  // views
  function claimDelay() external view returns (uint);
  function lastRoundIndex() external view returns (uint);
  function getRound(uint roundIndex) external view returns (Round memory);
  function players(address) external view returns (uint points, uint lastRoundPlayed);

  // view structs
  struct PlayHistory {
      address player;
      uint points;
      uint timestamp;
  }

  struct Round {
      uint lastCoronationTimestamp;
      address currentKing;
      uint totalPoints;
      uint winnings;
      PlayHistory[] plays;
  }

  // events
  event Burned(
        address indexed sender, uint indexed roundIndex, bool indexed isWinning, uint amount, uint gas
  );
  event GasFeesClaimed(uint amount);
  event NewRound(uint roundIndex);
  event RoundWon(address indexed winner, uint roundIndex, uint amount, uint winnerPoints, uint totalPoints);
}

Template stuff

If this is your first time with Foundry, check out the installation instructions.

Features

This template builds upon the frameworks and libraries mentioned above, so please consult their respective documentation for details about their specific features.

For example, if you're interested in exploring Foundry in more detail, you should look at the Foundry Book. In particular, you may be interested in reading the Writing Tests tutorial.

Sensible Defaults

This template comes with a set of sensible default configurations for you to use. These defaults can be found in the following files:

├── .editorconfig
├── .gitignore
├── .prettierignore
├── .prettierrc.yml
├── .solhint.json
├── foundry.toml
└── remappings.txt

VSCode Integration

This template is IDE agnostic, but for the best user experience, you may want to use it in VSCode alongside Nomic Foundation's Solidity extension.

For guidance on how to integrate a Foundry project in VSCode, please refer to this guide.

GitHub Actions

This template comes with GitHub Actions pre-configured. Your contracts will be linted and tested on every push and pull request made to the main branch.

You can edit the CI script in .github/workflows/ci.yml.

Installing Dependencies

Foundry typically uses git submodules to manage dependencies, but this template uses Node.js packages because submodules don't scale.

This is how to install dependencies:

  1. Install the dependency using your preferred package manager, e.g. bun install dependency-name
    • Use this syntax to install from GitHub: bun install github:username/repo-name
  2. Add a remapping for the dependency in remappings.txt, e.g. dependency-name=node_modules/dependency-name

Note that OpenZeppelin Contracts is pre-installed, so you can follow that as an example.

Writing Tests

To write a new test contract, you start by importing PRBTest and inherit from it in your test contract. PRBTest comes with a pre-instantiated cheatcodes environment accessible via the vm property. If you would like to view the logs in the terminal output you can add the -vvv flag and use console.log.

This template comes with an example test contract Foo.t.sol

Usage

This is a list of the most frequently needed commands.

Build

Build the contracts:

$ forge build

Clean

Delete the build artifacts and cache directories:

$ forge clean

Compile

Compile the contracts:

$ forge build

Coverage

Get a test coverage report:

$ forge coverage

Deploy

Deploy to Anvil:

$ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545

For this script to work, you need to have a MNEMONIC environment variable set to a valid BIP39 mnemonic.

For instructions on how to deploy to a testnet or mainnet, check out the Solidity Scripting tutorial.

Format

Format the contracts:

$ forge fmt

Gas Usage

Get a gas report:

$ forge test --gas-report

Lint

Lint the contracts:

$ bun run lint

Test

Run the tests:

$ forge test

Generate test coverage and output result to the terminal:

$ bun run test:coverage

Generate test coverage with lcov report (you'll have to open the ./coverage/index.html file in your browser, to do so simply copy paste the path):

$ bun run test:coverage:report

Related Efforts

License

This project is licensed under MIT.

blast-gas-king's People

Contributors

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