Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: CI

on:
push:
branches: [main, "feature/**"]
pull_request:
branches: [main]

jobs:
contracts:
name: Contracts (Build + Test + Fmt)
runs-on: ubuntu-latest
defaults:
run:
working-directory: contracts

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Install forge-std
run: forge install foundry-rs/forge-std --no-commit

- name: Build contracts
run: forge build --sizes

- name: Run tests
run: forge test -vvv

- name: Run fuzz tests (extended)
run: forge test --match-test "testFuzz" -vvv --fuzz-runs 500

- name: Check formatting
run: forge fmt --check

dashboard:
name: Dashboard (Lint + Typecheck + Build)
runs-on: ubuntu-latest
defaults:
run:
working-directory: dashboard

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
cache-dependency-path: dashboard/package-lock.json

- name: Install dependencies
run: npm ci

- name: TypeScript typecheck
run: npx tsc --noEmit

- name: Build
run: npm run build

sdk:
name: SDK (Typecheck + Build)
runs-on: ubuntu-latest
defaults:
run:
working-directory: sdk

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
cache-dependency-path: sdk/package-lock.json

- name: Install dependencies
run: npm ci

- name: TypeScript typecheck
run: npx tsc --noEmit

- name: Build
run: npm run build
245 changes: 245 additions & 0 deletions STRATEGY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
# FlashGrid: Startup Strategy Architecture

## Executive Summary

FlashGrid is a **state-sharded parallel batch auction engine** on Monad (~6,400 LOC). The core insight — isolating storage per price tick to enable true parallel execution — is a genuine architectural innovation. This document outlines the path from polished hackathon project to category-defining infrastructure.

**The billion-dollar reframe:** Don't be a prediction market. Be **parallel execution infrastructure** — the protocol + SDK that lets any DeFi team deploy parallel-native matching engines.

---

## 1. Uniqueness Analysis

### What's Actually Unique

The storage isolation pattern: mapping each tick to its own `TickState` struct so Monad's parallel execution doesn't hit write conflicts. Most DEX teams on parallel chains are still building traditional AMMs/CLOBs that serialize on shared state.

**Hidden strengths:**
- The pattern is **generalizable** — any on-chain system with contention hotspots could use tick-sharded state
- The benchmarking infrastructure (200-wallet load test + comparison contract) provides *measurable proof*
- The factory pattern hints at a multi-market platform

### What's Not Unique

- Prediction markets exist (Polymarket, Azuro, Overtime)
- Batch auctions exist (CoW Protocol, 1inch Fusion, UniswapX)
- "We're faster on Monad" is a temporary moat
- The settlement logic is simplified — real order books are 100x more complex

### Dangerous Assumptions

1. **"Monad will win"** — Entire thesis is Monad-specific
2. **"Parallelism = product"** — Speed is infra advantage, not user-facing feature
3. **"The hard part is the contract"** — The hard part is liquidity bootstrapping and regulatory positioning

---

## 2. Market Positioning

### Reframe: Parallel-Native DeFi Infrastructure

Don't compete in "prediction markets." Own the category of **primitives that actually use parallel execution** instead of running legacy code faster.

### Real Customers

| Customer | Why They Care |
|----------|---------------|
| **Monad itself** | Needs flagship apps proving parallelism matters |
| **Market makers** | Need infrastructure that doesn't serialize strategies |
| **DeFi protocol teams** | Don't know how to architect for parallelism |
| **Prediction market aggregators** | Need backends for Polymarket-scale on-chain volume |
| **MEV searchers** | Sharded state = new extraction patterns |

### The Painful Problem at Scale

Every DeFi protocol on Monad/Sei/MegaETH will hit the same wall: their architecture serializes on shared state, negating parallelism. They need a framework to redesign around.

---

## 3. Billion-Dollar Architecture

### Protocol + SDK Model (Uniswap Labs playbook)

```
1. PROTOCOL LAYER (open, forkable)
- FlashGrid Protocol: state-sharded matching primitives
- Becomes the "ERC-4626 of parallel matching"

2. SDK/TOOLING LAYER (value capture)
- FlashGrid SDK: deploy parallel-native markets in <100 LOC
- Indexer-as-a-service for sharded state
- Analytics + benchmarking tools

3. NETWORK EFFECTS
- Shared liquidity across FlashGrid-powered markets
- Cross-market routing
- Composability = lock-in
```

---

## 4. Production Architecture

```
┌─────────────────────────────────────────────────────┐
│ FlashGrid Protocol │
├──────────┬──────────┬──────────┬────────────────────┤
│ Core │ Markets │ Routing │ Settlement │
│ Engine │ Registry │ Layer │ Engine │
│ (sharded │ (factory │ (cross- │ (pluggable: │
│ ticks) │ + meta) │ market) │ pro-rata, CLOB, │
│ │ │ │ batch auction) │
├──────────┴──────────┴──────────┴────────────────────┤
│ Indexer / Event Bus │
│ PostgreSQL + Redis (not in-memory) │
├─────────────────────────────────────────────────────┤
│ SDK / API Layer │
│ TypeScript SDK │ REST API │ WebSocket Subscriptions│
├─────────────────────────────────────────────────────┤
│ Frontend Layer │
│ Embeddable widgets │ Reference dashboard │ Docs │
└─────────────────────────────────────────────────────┘
```

### Critical Changes from Current State

| Current | Production | Why |
|---------|------------|-----|
| In-memory event store | PostgreSQL + Redis | Persistence, horizontal scaling |
| Polling (2s) | WebSocket subscriptions | Real-time UX, lower load |
| Single contract | UUPS upgradeable proxy | Bug fixes without redeployment |
| Hardcoded 20 ticks | Configurable per market | Different markets need different granularity |
| No keepers | Gelato/Chainlink Automation | Permissionless settlement |
| No oracle | Chainlink/Pyth integration | Trustless resolution |
| Mnemonic wallets | Hardware wallet + multisig | Production key management |

### Security Requirements

- Formal verification (Halmos/Certora) for matching/settlement
- Explicit `nonReentrant` guards
- MEV protection formalization
- Minimum order sizes (prevent dust order gaming)
- Off-chain API rate limiting

---

## 5. Execution Roadmap

### v0: Current to MVP (Weeks 1-6)

**Goal:** Usable prediction market on Monad testnet with real users.

**Features:**
- Oracle-based market resolution
- Persistent indexer (PostgreSQL)
- WebSocket real-time updates
- Order management (cancel, modify)
- Mobile-responsive dashboard

**Risks:** Monad testnet instability, oracle integration complexity

### v1: Product-Market Fit (Months 2-4)

**Goal:** 1,000 active traders. Prove parallel execution = better UX.

**Features:**
- Multi-market support (sports, crypto, politics)
- SDK v1: `npm install @flashgrid/sdk`
- Liquidity mining program
- Automated settlement via keepers
- Pluggable settlement strategies

**Risks:** Liquidity cold-start, Monad mainnet timing, regulatory risk

### v2: Scale (Months 5-12)

**Goal:** Default matching infrastructure on Monad. Multi-chain expansion.

**Features:**
- Formalized, audited FlashGrid Protocol
- Multi-chain (Sei, MegaETH, Aptos)
- Cross-chain liquidity routing
- Institutional API
- Governance token + DAO
- Embeddable widgets

**Risks:** Multi-chain complexity (3x engineering), governance regulatory scrutiny, forkability

### v3: Dominance (Year 2+)

**Goal:** Standard primitive for parallel matching (like Uniswap for AMMs).

**Features:**
- ERC-standard proposal
- Composable with lending/derivatives
- White-label for TradFi
- Revenue: protocol fees, SDK licensing, managed infra

**Risks:** Parallel chain adoption uncertainty, TradFi sales cycles, well-funded competitors

---

## 6. Distribution Strategy

### Phase 1: Ecosystem Alignment
- Monad grants program — become the "reference parallel DeFi app"
- Technical content: publish benchmarks as blog posts and Twitter threads
- Every Monad dev tutorial should reference state-sharding pattern

### Phase 2: Developer Adoption
- `npx create-flashgrid-market` — trivially easy market deployment
- Hackathon sponsorship with bounties
- Open-source protocol; monetize tooling

### Phase 3: Trader Acquisition
- High-interest markets (elections, crypto, sports)
- Referral program with fee rebates
- Aggregator integrations

### Channel Priority

| Channel | Priority |
|---------|----------|
| Crypto Twitter / technical content | HIGH |
| Monad ecosystem/grants | HIGH |
| Hackathon sponsorship | MEDIUM |
| DeFi aggregator integrations | MEDIUM |
| Conference talks | LOW (early) |

---

## 7. Risk Assessment

### Why This Might Fail

1. **Monad dependency is existential** — binary risk that can't be hedged without multi-chain
2. **Parallelism advantage may be invisible to users** — "5x orders/block" ≠ better fills
3. **Liquidity is the only DeFi moat, and there is none** — Polymarket has $500M+ TVL
4. **Prediction markets have severe regulatory risk** — Kalshi spent years on CFTC
5. **Pattern is trivially forkable** — 200-line insight, copyable in a weekend

### Overestimated

- Importance of parallelism to end users
- Difficulty of copying the approach
- Monad's timeline and adoption
- Value of benchmarks to traders

### Underestimated

- Power of the SDK/protocol play (bigger opportunity than the app)
- Difficulty of liquidity bootstrapping (budget 60% of early effort)
- Regulatory complexity (get legal counsel pre-launch)
- Value of the Monad relationship (reference app = free distribution)

---

## 8. The Strategic Pivot

**The prediction market is the demo app. The protocol + SDK is the product.**

This reframing:
- Eliminates prediction market regulatory risk from core business
- Expands TAM from "prediction market users" to "all DeFi on parallel chains"
- Creates defensibility through developer ecosystem
- Aligns with how billion-dollar crypto companies work (Uniswap, Aave, Chainlink — protocols, not apps)
7 changes: 7 additions & 0 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ optimizer_runs = 200
line_length = 120
tab_width = 4

[profile.default.fuzz]
runs = 256

[rpc_endpoints]
monad_testnet = "https://testnet-rpc.monad.xyz"
sepolia = "${SEPOLIA_RPC_URL}"
base_sepolia = "${BASE_SEPOLIA_RPC_URL}"

[etherscan]
monad_testnet = { key = "", url = "https://testnet.monadvision.com/api" }
sepolia = { key = "${ETHERSCAN_API_KEY}", url = "https://api-sepolia.etherscan.io/api" }
base_sepolia = { key = "${BASESCAN_API_KEY}", url = "https://api-sepolia.basescan.org/api" }
5 changes: 3 additions & 2 deletions contracts/script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import {ParallelBenchmark} from "../src/ParallelBenchmark.sol";
contract DeployScript is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
address deployer = vm.addr(deployerPrivateKey);
vm.startBroadcast(deployerPrivateKey);

// 1. Deploy Factory
FlashGridFactory factory = new FlashGridFactory();
console2.log("FlashGridFactory deployed at:", address(factory));

// 2. Create default market via factory
// 2. Create default market (deployer is resolver)
address market = factory.createMarket("Will MON reach $10 by Q2 2025?");
console2.log("FlashGrid market deployed at:", market);

Expand All @@ -24,10 +25,10 @@ contract DeployScript is Script {

vm.stopBroadcast();

// Output addresses for scripts
console2.log("\n=== Deployment Summary ===");
console2.log("Factory: ", address(factory));
console2.log("Market: ", market);
console2.log("Resolver: ", deployer);
console2.log("Benchmark: ", address(benchmark));
console2.log("Chain ID: ", block.chainid);
}
Expand Down
Loading
Loading