/ChessWager

Bet on live professional chess games

Primary LanguageTypeScriptGNU Affero General Public License v3.0AGPL-3.0

ChessWager is a highly performant hybrid dApp that uses smart contracts to securely facilitate betting on the top professional games being played on LichessTV

License PRs Welcome

ChessWager is live. A mainnet currency is not supported yet, but you can play on the Avalanche testnet. Download Metamask, switch to the Avalanche Testnet, and add some test currency to play at https://chesswager.io/.

Data Flow

The client relies on a Firestore serverless infrastructure. When a page loads, the client subscribes to the LichessTV API and loads real-time data about chats, bets, and users from the Firestore database. For performance reasons, the browser never loads data directly from the contract.

A few distinct programs run in an isolated cloud environment to interact with the smart contract. One of those programs listens for user payments on the smart contract. Once two users agree to a wager, their Metamask wallets will prompt each user with the appropriate amount. When a user sends a transaction to the contract, the contract listener writes an update to the Firestore database. These changes are reflected immediately in the UI, visually informing users that their payment was received. When a bet is matched, the conditions of the bet are compared in the smart contract. If the values don't perfectly match, the transaction is rejected.

Another isolated backend program subscribes to the LichessTV API. At the end of each game, that program interacts with the smart contract telling it to complete the bet transactions paying the winners or refunding users accordingly.

This system emphasizes speed and responsiveness by using centralized systems for bet pairing and user interactions. However, many benefits of decentralization are maintained through the smart contracts ensuring that users' funds are secured and only payable to the respective accounts that placed the bet. The service is entirely non-custodial, meaning that chesswager never actually possesses your funds; they are instead stored in the smart contract on the blockchain for the duration of the bet.

Performance

These benchmark results are from Google's Lighthouse auditing tool.

  • Users can consistently expect payout within 5 seconds of a game ending.
  • Database load times are ususally between 50-100ms.
  • Less than 25MB of the client's system memory is used under peak loads.

Lighthouse warns "There may be stored data affecting loading performance in this location: IndexedDB". There seems to be no way to test this app without getting that warning, even in a private tab.
Lighthouse warns "The page loaded too slowly to finish within the time limit. Results may be incomplete". This is because the continuous data stream from lichess stays open.

Roadmap

We are nearing the end of phase 2. Our primary features are functional and complete. Most behaviors are thoroughly tested. All that remains are a few tests, making some elements responsive so they look better on smaller displays, new user onboarding guides, and some customer service options so we can know if something goes wrong.

Primary Technologies

Build & Package Management

Yarn Vite

Frontend

TypeScript React TailwindCSS Ethers

Backend

TypeScript NodeJS Solidity Avalanche Firebase

Testing

Cypress Jest Chai Hardhat Waffle

Cloud

Google Cloud Docker Kubernetes GKE Cloud Build

Contributions

This repository's branch structure is designed similarly to the standard gitflow model with the addition of a "test" branch between develop and release. The develop, test, and main branches each have their own backend environment. The test branch serves as a safe way for us to test features.

  • Develop could have any environmental changes at any time.
  • Test will only have user testing and controlled tests running on its environment during the build process.
  • Main operates in the production environment.

If you would like to contribute to this repo, start by opening an issue so we can discuss the feature. Create a feature branch from develop and make a pull request into develop when you're done.

For style and linting, there is a prettier config file as well as a tailwind plugin for prettier in the dev dependencies. We use Cypress for our frontend testing, Jest for the backend, and hardhat+waffle on smart contracts. The testing requirements are that all behaviors should be tested before release, not necessarily every line of code.

Values

Values are subject to evolution and change at this point, but it is paramount to establish the desired culture early. You may have heard of some of these before, but I'm taking what I like from top companies:

  1. Customer Obsession - Amazon is famous for this. Without any customers, there's no business. Customers are simply the most important part of the equation. That means keeping our services clean and friendly. We will strive to deliver the best experience through customer service and a quality product.
  2. Code Standards - Robert "Uncle Bob" Martin influenced this one. We promise never to release code whose behavior is not well tested. A bug will never knowingly make its way into production.
  3. Don't Be Evil - Google used to say this, and we agree that businesses should not leave a negative impact. We will never implement anti-consumer mechanisms or knowingly cause harm.
  4. Treat Everyone with Respect and Dignity - We will always be respectful internally and externally, even in the face of obscenity. That means customers, employees, and strangers.
Feedback is welcome