
MortalCoin
Outtrade your opponent to win.
Demo
About
The problem it solves # MortalCoin: Turning Trading Into Combat The Web3 world thrives on trading, competition, and gaming — yet these elements rarely intersect. Trading is often solitary and chart-focused, while gaming and meme culture operate in parallel. **MortalCoin** unifies these worlds into a real-time, skill-based battleground where cryptocurrencies become playable characters. Inspired by the speed of **Hyperliquid**, the depth of **poker**, and the intensity of **Mortal Kombat**, it transforms speculative trading into fast-paced, strategic combat. Players face off in PvP or PvE matches, "fighting" by outperforming opponents in simulated trading rounds using real-time price feeds. Each token is a fighter, giving personality to assets and making trading more engaging and emotional. --- ## How It Works ### Smart Contracts All core gameplay actions — from creating games to settling results — are on-chain via EVM-compatible smart contracts. This ensures transparency and resistance to manipulation. ### Backend Support The backend helps manage the experience: - Validates on-chain actions - Relays messages and trading signatures between players - Tracks matchmaking and game state - Detects inactive players and removes stale games ### Frontend Flow Players select a fighter, enter matchmaking, and trade in real-time during 60-second rounds. Moves are recorded on-chain: - Positions are hashed when opened and revealed only when closed - Final PnL determines the winner, who takes the full reward minus a small fee --- ## Key Gameplay Mechanics - **Start Fight**: Create or join a game with a small bet - **Real-Time Trading**: Simulated long/short trading based on real DEX prices - **Hidden Moves**: Trade directions are hashed to prevent front-running - **Finalization**: When both players close positions, the winner is determined automatically --- ## Security & Fairness - Only approved DEX pools can be used for price feeds - Smart contracts enforce all game logic - Backend monitors player activity and helps prevent abuse Smart Contract Address(es) https://sepolia.basescan.org/address/0x5d087835E5f834315F925C394271c503d690443D Other Onchain Proof Marketmaking addy: https://sepolia.basescan.org/address/0xabd1e33e6F78f9bdAA0724762C6A51a0c71ad8F9
How it's made
Challenges we ran into # Key Challenges ## 1. Matchmaking and the PvP Challenge Since the game is PvP, the main challenge is matchmaking. If a player creates a game and no one joins — that's a blocker, especially during the early stages of the project when user activity is low. To solve this, we're working on a **matchmaking bot** that plays by trading using AI. It acts as a kind of agent filling the role of an opponent. **Repo:** https://github.com/MortalCoin/mortalcoin_alith_bot The bot constantly monitors the matchmaking lobby, joins open games, listens to the ongoing game state (real-time prices, opponent actions, etc.), and tries to make good decisions based on its assigned role. ## 2. Price Feeds and Market Simulation Another major challenge is the price feed. To make the game fun, prices must move often enough and reflect meaningful market behavior — while remaining accurate. Technically, it’s possible to integrate real asset trading instead of paper trading, but: - It complicates the game and pushes it toward being more of a gamified trading wrapper (not necessarily bad — could be explored separately) - It requires a liquid **perpetual market** to support both long and short positions - Prices must be reliable and update on very short timeframes (e.g., per second or even tick-level) We haven’t found a suitable decentralized solution suitable for POC (like an oracle refreshing fast enough), so for testnet we built our own **market-making bot** that simulates price movement on AMM DEX pairs - effectively acting as an in-house oracle. **Repo:** https://github.com/MortalCoin/mortalcoin-dex-bot ## 3. Gameplay Depth via Hidden Information I wanted to make the game interesting, adding elements of **partially hidden information**, similar to poker. If all variables are visible — current price, realized PnL, positions (yours and your opponent's) — it turns into a deterministic equation-solving task rather than a game. So, in MortalCoin, you only know whether the opponent has opened a position — but **not the direction** (long or short). This creates tension and strategy. To support this, we implemented a system where positions are **hashed** with a backend key before being sent on-chain. The flow is: - Player sends an EIP-712 object with position details to the backend - Backend hashes the position and signs it - Player submits the hashed version to the smart contract - Direction is only revealed when the player closes the position This prevents sniping and adds a layer of strategy. ## 4. Incomplete Games and Forced Finalization One more big challenge: **non-finished games**, whether abandoned on purpose or due to connection loss. The contract calculates PnL based on the price at the time of position closing, which opens a potential exploit where a malicious player might avoid closing their position to lock in a win or deny the opponent’s reward. To prevent this, we added a `forceFinish` function to the contract. Our backend watcher monitors all ongoing games and triggers `forceFinish` for any game that wasn’t completed in time. It was also tricky to implement a reliable system for storing nonces and direction data on the backend side, so we could finalize games even when one player is unresponsive. --- ## Game Flow: Sequence Diagram 