Skip to content

unspecifiedcoder/FlashGrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FlashGrid: Parallel Batch Auction Engine on Monad

A state-sharded order matching engine that settles hundreds of orders per block across isolated price ticks — proving Monad's parallel execution isn't theoretical, it's measurable.

Architecture

┌─────────────────────────────────────────────────────┐
│                    FlashGrid                         │
│                                                      │
│  ┌──────────┐   ┌──────────┐   ┌──────────┐        │
│  │ Tick 0.10│   │ Tick 0.25│   │ Tick 0.50│  ...    │  ← Each tick = isolated state
│  │ [orders] │   │ [orders] │   │ [orders] │         │    No storage conflicts
│  └────┬─────┘   └────┬─────┘   └────┬─────┘        │    Monad executes in parallel
│       │              │              │                │
│       ▼              ▼              ▼                │
│  ┌─────────────────────────────────────────┐        │
│  │         BatchSettlement.sol              │        │
│  │   Epoch-based: collect → match → settle │        │
│  └─────────────────────────────────────────┘        │
│                      │                               │
│                      ▼                               │
│  ┌─────────────────────────────────────────┐        │
│  │         Events → Indexer → Dashboard     │        │
│  │   Real-time parallel execution metrics   │        │
│  └─────────────────────────────────────────┘        │
└─────────────────────────────────────────────────────┘

Why State-Sharding Works on Monad

Monad's parallel execution engine detects storage slot conflicts at runtime. If two transactions touch the same slot, one re-executes.

  • Traditional AMM: Every swap touches the same reserve0/reserve1 slots → serial execution
  • FlashGrid: Orders at tick 0.10 write to mapping(uint8 => TickState)[10], orders at tick 0.50 write to ...[50]zero conflicts → full parallelism

Quick Start

Dashboard Experience

The dashboard is built to make Monad's parallel execution visible in real time, not just claim it in a benchmark table.

  • Light, Apple-inspired UI with a neutral palette for long demo sessions
  • Live order feed showing recent on-chain order placement as it lands
  • Canvas heatmap showing liquidity concentration across isolated price ticks
  • Metrics and comparison charts that make the sharded-vs-sequential story obvious
  • One-click demo mode for judges who want to see the full flow without funding a wallet

The redesigned dashboard lives in dashboard/ and talks directly to Monad testnet through the app API routes.

Prerequisites

1. Setup

# Clone the repo
git clone <repo-url>
cd flashgrid

# Install dashboard dependencies
cd dashboard && npm install && cd ..

# Install script dependencies
cd scripts && npm install && cd ..

# Install Foundry deps
cd contracts && forge install && cd ..

2. Configure Environment

# Copy env example
cp .env.example .env

# Edit .env with your private key and contract addresses

3. Compile & Test Contracts

cd contracts
forge build
forge test -vvv

4. Deploy to Monad Testnet

cd contracts
forge script script/Deploy.s.sol --rpc-url https://testnet-rpc.monad.xyz --broadcast

Update .env and dashboard/.env.local with deployed addresses.

5. Run Load Test

cd scripts

# Fund test wallets
npx tsx fund-wallets.ts

# Run FlashGrid load test
npx tsx load-test.ts sharded

# Run comparison (sharded vs sequential)
npx tsx compare.ts

6. Launch Dashboard

cd dashboard
npm run dev

Open http://localhost:3000

Project Structure

flashgrid/
├── contracts/
│   ├── src/
│   │   ├── FlashGrid.sol           # Core engine (~130 LOC)
│   │   ├── FlashGridFactory.sol    # Market deployer (~40 LOC)
│   │   └── ParallelBenchmark.sol   # Sequential baseline (~30 LOC)
│   ├── test/
│   │   └── FlashGrid.t.sol         # Foundry tests
│   ├── script/
│   │   └── Deploy.s.sol            # Deployment script
│   └── foundry.toml
├── scripts/
│   ├── load-test.ts                # 200-wallet parallel load test
│   ├── fund-wallets.ts             # Batch fund test wallets
│   └── compare.ts                  # Run both tests + format results
├── dashboard/
│   ├── app/
│   │   ├── page.tsx                # Main 4-panel dashboard
│   │   └── api/                    # Event indexer API routes
│   ├── components/
│   │   ├── Heatmap.tsx             # Order book heatmap (canvas)
│   │   ├── OrderFeed.tsx           # Live event stream
│   │   ├── MetricsPanel.tsx        # Execution gauges + charts
│   │   └── ParallelChart.tsx       # Before/after comparison
│   └── lib/
│       ├── contract.ts             # ABI + addresses
│       ├── indexer.ts              # Event polling + in-memory store
│       └── types.ts                # Shared types
└── plan.md

Smart Contracts

Contract Purpose Key Feature
FlashGrid.sol Core order matching engine 20 isolated tick storage slots
FlashGridFactory.sol Market deployer CREATE2 deterministic deployment
ParallelBenchmark.sol Sequential baseline Single-slot bottleneck for comparison

Parallelism Design

Function Gas Target Parallelism
deposit() ~25k Touches only balances[msg.sender]
placeOrder(tick, amount, isYes) ~45k Touches only ticks[tick] + tickOrders[tick]
settleTick(tick) ~80k Touches only that tick's state
settleAll() Loops Calls settleTick per tick — each parallelizable

Tech Stack

Layer Technology
Contracts Solidity 0.8.24 + Foundry
Frontend Next.js 15 + Tailwind + Recharts
Chain Interaction viem
Indexer Next.js API routes + in-memory cache
Load Testing Custom TS scripts with viem

Network

Network Monad Testnet
RPC https://testnet-rpc.monad.xyz
Chain ID 10143
Symbol MON
Explorer https://testnet.monadvision.com
Faucet https://faucet.monad.xyz

License

MIT

About

A state-sharded order matching engine with commit-reveal MEV protection and autonomous AI market-making agents

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors