Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Flash V2 starter — copy to .env. Defaults work immediately. MAINNET = real funds.

# Hosted Flash V2 API.
FLASH_V2_BASE_URL=https://flashapi.trade/v2
FLASH_V2_BASE_URL=https://flashapi.trade

# Ephemeral Rollup RPC — TRADING transactions go here.
ER_RPC_URL=https://flash.magicblock.xyz
Expand Down
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ You are probably here because someone said "build me a tap-trading app on
Flash V2". The complete known-good recipe:

1. **Network = mainnet.** Flash V2 is live on Solana mainnet
(`https://flashapi.trade/v2`). Real funds — default position sizes small.
(`https://flashapi.trade`). Real funds — default position sizes small.
2. **Env (`examples/tap-trade/.env.local`, gitignored):** copy
`.env.example`, then set your own CORS-friendly RPC (a free helius.dev /
triton.one key) as `NEXT_PUBLIC_BASE_RPC`; it ships in the browser bundle,
Expand All @@ -74,7 +74,7 @@ Flash V2". The complete known-good recipe:
deposit/withdraw actions with a user-typed amount and a dedicated wallet
approval (`examples/tap-trade/lib/funds.ts`, GOTCHAS §19). Never bundle a
transfer into a convenience flow; never display an unlabeled balance.
5. **Markets are dynamic:** `GET /v2/tokens` is Flash's live config (every
5. **Markets are dynamic:** `GET /tokens` is Flash's live config (every
non-stable token is a market — SOL, BTC, ETH, ZEC, HYPE, equities…). Read
it at runtime; never hardcode the list.
6. **Withdraw is two steps:** `request-withdrawal` → `execute-withdrawal`
Expand Down
2 changes: 1 addition & 1 deletion GOTCHAS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Each entry below is a real sharp edge of building on Flash V2, written as **symp
## 7. The WS sends two frame types — merge them or go stale

**Symptom:** PnL updates but orders/basket bytes freeze (or vice versa).
**Why:** `/v2/owner/{owner}/ws` sends `{type:"basket"}` (full snapshot, on real on-chain change) and `{type:"metrics"}` (positions-only, every oracle tick). Metrics frames do **not** include orders.
**Why:** `/owner/{owner}/ws` sends `{type:"basket"}` (full snapshot, on real on-chain change) and `{type:"metrics"}` (positions-only, every oracle tick). Metrics frames do **not** include orders.
**Fix:** fold `metrics` into the last `basket` state — `subscribeOwner()` does the merge for you.

## 8. WS connection limits are real
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Clone to your first ephemeral-rollup trade in minutes. Mainnet — real funds.

[![CI](https://github.com/flash-trade/examples-v2/actions/workflows/ci.yml/badge.svg)](https://github.com/flash-trade/examples-v2/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-22c55e?style=flat)](./LICENSE)
[![API](https://img.shields.io/badge/API-live-fbbf24?style=flat)](https://flashapi.trade/v2/health)
[![API](https://img.shields.io/badge/API-live-fbbf24?style=flat)](https://flashapi.trade/health)
[![Network](https://img.shields.io/badge/mainnet-default-3b82f6?style=flat)](#networks)
[![Solana](https://img.shields.io/badge/Solana-perpetuals-9945FF?style=flat&logo=solana)](https://flash.trade)
[![MagicBlock](https://img.shields.io/badge/MagicBlock-Ephemeral_Rollups-a855f7?style=flat)](https://docs.magicblock.gg)
Expand All @@ -30,7 +30,7 @@ Clone to your first ephemeral-rollup trade in minutes. Mainnet — real funds.
No clone, no auth — the API is live right now:

```bash
curl https://flashapi.trade/v2/prices/SOL
curl https://flashapi.trade/prices/SOL
```

Then make it yours:
Expand Down Expand Up @@ -115,7 +115,7 @@ Mainnet. Real funds — size positions accordingly.

| | |
|---|---|
| V2 API | `https://flashapi.trade/v2` |
| V2 API | `https://flashapi.trade` |
| ER RPC (trading) | `https://flash.magicblock.xyz` |
| Base RPC (setup/withdraw) | your own keyed RPC (the public one rate-limits) |

Expand Down
6 changes: 3 additions & 3 deletions examples/_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ Whatever you want — this folder is the starting point. It ships doing the thre

| Endpoint | Why |
|---|---|
| `GET /v2/prices/{symbol}` | live oracle read |
| `POST /v2/transaction-builder/open-position` (no owner) | free quote API |
| `GET /v2/owner/{owner}` + `/ws` | live positions via `subscribeOwner` |
| `GET /prices/{symbol}` | live oracle read |
| `POST /transaction-builder/open-position` (no owner) | free quote API |
| `GET /owner/{owner}` + `/ws` | live positions via `subscribeOwner` |

## Run it

Expand Down
2 changes: 1 addition & 1 deletion examples/copy-trade/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ NEXT_PUBLIC_ER_RPC=https://flash.magicblock.xyz
# FSTATS_BASE=https://fstats.io/v2/api/v1

# Override the hosted Flash V2 API (rarely needed).
# NEXT_PUBLIC_FLASH_API_BASE=https://flashapi.trade/v2
# NEXT_PUBLIC_FLASH_API_BASE=https://flashapi.trade
8 changes: 4 additions & 4 deletions examples/copy-trade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ A follower bot that watches any wallet's live Flash V2 positions and mirrors its

| Endpoint | Why |
|---|---|
| `GET /v2/owner/{LEADER}` + `/ws` | the leader's live positions (the diff source) |
| `GET /v2/owner/{follower}` | follower collateral for ratio sizing |
| `POST /v2/transaction-builder/open-position` | mirror opens/grows |
| `POST /v2/transaction-builder/close-position` | mirror shrinks/closes ("0" = full) |
| `GET /owner/{LEADER}` + `/ws` | the leader's live positions (the diff source) |
| `GET /owner/{follower}` | follower collateral for ratio sizing |
| `POST /transaction-builder/open-position` | mirror opens/grows |
| `POST /transaction-builder/close-position` | mirror shrinks/closes ("0" = full) |

## Run it

Expand Down
2 changes: 1 addition & 1 deletion examples/copy-trade/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function usePrice(symbol: string, intervalMs = 1000): {
}

/**
* The tradeable market list, LIVE from Flash's own config (`GET /v2/tokens` —
* The tradeable market list, LIVE from Flash's own config (`GET /tokens` —
* CDN-driven and hot-reloaded server-side): every non-stable token in the
* active pool is a market. New listings appear here automatically.
* Returns null until loaded (callers keep a static fallback meanwhile).
Expand Down
2 changes: 1 addition & 1 deletion examples/copy-trade/lib/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const SESSION_KEYS_PROGRAM = new PublicKey("KeyspM2ssCJbqUhQ4k7sveSiY4Wjn
/**
* magic-trade (Flash V2 on MagicBlock) program — the session target.
* Mainnet: FTv2RxXarPfNta45HTTMVaGvjzsGg27FXJ3hEKWBhrzV
* (verified by decoding a mainnet init-basket transaction from /v2/transaction-builder)
* (verified by decoding a mainnet init-basket transaction from /transaction-builder)
*/
/** magic-trade program (mainnet) — decoded from live builder txs. */
export const MAGIC_TRADE_PROGRAM = new PublicKey("FTv2RxXarPfNta45HTTMVaGvjzsGg27FXJ3hEKWBhrzV");
Expand Down
2 changes: 1 addition & 1 deletion examples/predict/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ NEXT_PUBLIC_BASE_RPC=https://mainnet.helius-rpc.com/?api-key=YOUR_KEY_HERE
NEXT_PUBLIC_ER_RPC=https://flash.magicblock.xyz

# Override the hosted Flash V2 API (rarely needed).
# NEXT_PUBLIC_FLASH_API_BASE=https://flashapi.trade/v2
# NEXT_PUBLIC_FLASH_API_BASE=https://flashapi.trade
10 changes: 5 additions & 5 deletions examples/predict/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## What you'll build

A single-screen price-call game: pick a market (live from `/v2/tokens`), pick UP or DOWN, pick a timeframe, stake USDC. The ticket shows your numbers *before* you sign — payoff per 1% move, break-even, knockout level, max loss (= your stake) — locks them at commit, and settles the round from your browser at expiry. Wins land in your basket; history keeps the receipts.
A single-screen price-call game: pick a market (live from `/tokens`), pick UP or DOWN, pick a timeframe, stake USDC. The ticket shows your numbers *before* you sign — payoff per 1% move, break-even, knockout level, max loss (= your stake) — locks them at commit, and settles the round from your browser at expiry. Wins land in your basket; history keeps the receipts.

## What's tricky here

Expand All @@ -31,12 +31,12 @@ Timeframe → payout profiles: **5m → ×5, 15m → ×3.3, 1h → ×2**, clampe

| Endpoint | Why |
|---|---|
| `GET /v2/tokens` | live market list (never hardcoded) |
| `GET /v2/prices/{symbol}` | ticket price + live PnL mark |
| `GET /tokens` | live market list (never hardcoded) |
| `GET /prices/{symbol}` | ticket price + live PnL mark |
| `POST open-position` (no `owner`) | the free quote at the review gate |
| `POST open-position` | the round itself (session-signed → ER RPC) |
| `POST close-position` (`"0"`) | settlement — explicit FULL close |
| `GET /v2/owner/{owner}/ws` | live positions (one shared `subscribeOwner`) |
| `GET /owner/{owner}/ws` | live positions (one shared `subscribeOwner`) |
| `init-basket` / `init-deposit-ledger` / `delegate-basket` / `deposit-direct` | Enable + deposit (base chain) |
| `request-withdrawal` / `execute-withdrawal` | two-phase exit (base chain) |

Expand All @@ -61,6 +61,6 @@ This is an open-source example. Before running it as a *service* for other peopl
- **Jurisdictions are your problem.** Comparable products geo-fence: PancakeSwap Prediction hard-blocks restricted regions (HTTP 451), dYdX/Hyperliquid block US/UK/Canada IPs and prohibit VPN circumvention in their ToU. Several countries classify prediction-style products as gambling (Singapore, Indonesia, Spain, others). Get advice, geofence accordingly, and put a Restricted-Persons clause in your terms.
- **Adopt the loss-disclosure banner.** ESMA/FCA require "X% of retail accounts lose money" for CFD-like retail products; this app ships a voluntary version in the footer. Keep it.
- **Protect your RPC key.** `NEXT_PUBLIC_BASE_RPC` ships in the browser bundle — use a domain-restricted key, or better, a server-side proxy (e.g. Helius's one-click worker). Add a fallback provider; map 429s to calm copy (already done in `lib/copy.ts`).
- **Add error monitoring** (Sentry + source maps) and uptime checks on `https://flashapi.trade/v2/health`.
- **Add error monitoring** (Sentry + source maps) and uptime checks on `https://flashapi.trade/health`.
- **Keeper settlement.** Client-side settlement is honest but depends on the user returning. A production service should run a keeper that closes expired rounds server-side — that requires a delegated signing design (users' session keys must never leave their browser; consider per-round TP/SL brackets via `place-tp-sl` as a chain-side backstop instead).
- **Known future work:** touch-mode rounds (TP/SL bracket = near-binary payoff, `validateTriggerPrice` + the $11 floor already enforced), shared leaderboards (needs an indexer), Mobile Wallet Adapter flows for Android/iOS.
4 changes: 2 additions & 2 deletions examples/predict/SPEC-PREDICT-V2.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Engine surface (all pure, typechecked):
## The UX (Kalshi/Polymarket-grade, on the existing dark glass)

Screens:
1. **Discover** — category tabs (Crypto / Stocks / FX / Commodities, from `/v2/tokens`) + search + a **market-card grid**. Card = question · big YES/NO ¢ · a YES/NO split bar · countdown · sparkline · volume-ish. (The single most important component — make it instantly scannable + clickable.)
1. **Discover** — category tabs (Crypto / Stocks / FX / Commodities, from `/tokens`) + search + a **market-card grid**. Card = question · big YES/NO ¢ · a YES/NO split bar · countdown · sparkline · volume-ish. (The single most important component — make it instantly scannable + clickable.)
2. **Market detail** — the question, a **probability-over-time line chart** (reuse `usePriceHistory`, plot implied prob), the strike ladder / bucket outcomes as rows, and the **buy ticket**.
3. **Buy ticket** — YES/NO toggle, amount, **avg price (¢), shares, "To win $X", max loss = your stake**, the locked-numbers confirm ("these don't drift"). Honest, never manipulative.
4. **Portfolio** — open positions as shares with live value (mark→implied prob), realized history, a local leaderboard/stats (inherit `stats-strip` / `history`).
Expand All @@ -65,7 +65,7 @@ Keep the existing "Void Instrument / frosted glass" base (`globals.css`, `DESIGN
## Build phases (sequential; subagents rate-limited until Jun 15 9am ET)

1. ✅ **Odds engine** — `lib/markets.ts` (pure, typechecked).
2. **Market model + state** — extend `lib/rounds.ts` for share/market rounds; a `useMarkets`-style hook that builds ladders/buckets from live `/v2/tokens` + `/v2/prices`; the `openParamsFor` → confirm/lock flow.
2. **Market model + state** — extend `lib/rounds.ts` for share/market rounds; a `useMarkets`-style hook that builds ladders/buckets from live `/tokens` + `/prices`; the `openParamsFor` → confirm/lock flow.
3. **Discover + market card** — the category/search grid + the card component (the highest-leverage UI).
4. **Market detail + buy ticket** — prob chart + ladder/bucket rows + the YES/NO ticket with "to win $X" / max-loss.
5. **Portfolio + settlement** — shares with live value, history, the welcome-back settle adapted to win/lose framing.
Expand Down
2 changes: 1 addition & 1 deletion examples/predict/components/bets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// never the indexer pnl) + a countdown to the deadline + a manual settle; SETTLED
// bets show WON/LOST. The position is the truth — the round adds the framing. The
// settlement engine (useMarketRounds) auto-closes at the deadline; "settle" is the
// manual override. Marks come from one polled /v2/prices.
// manual override. Marks come from one polled /prices.
// ─────────────────────────────────────────────────────────────────────────────

"use client";
Expand Down
2 changes: 1 addition & 1 deletion examples/predict/components/discover.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ─────────────────────────────────────────────────────────────────────────────
// components/discover.tsx — the market browser: category tabs + search +
// timeframe + a grid of MarketCards. Browsing needs NO wallet (markets are
// public: /v2/tokens + /v2/prices). Tapping a card hands (token, price, tf) up
// public: /tokens + /prices). Tapping a card hands (token, price, tf) up
// to open the detail + ticket (phase 4).
// ─────────────────────────────────────────────────────────────────────────────

Expand Down
2 changes: 1 addition & 1 deletion examples/predict/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function usePrice(symbol: string, intervalMs = 1000): {
}

/**
* The tradeable market list, LIVE from Flash's own config (`GET /v2/tokens` —
* The tradeable market list, LIVE from Flash's own config (`GET /tokens` —
* CDN-driven and hot-reloaded server-side): every non-stable token in the
* active pool is a market. New listings appear here automatically.
* Returns null until loaded (callers keep a static fallback meanwhile).
Expand Down
2 changes: 1 addition & 1 deletion examples/predict/lib/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const SESSION_KEYS_PROGRAM = new PublicKey("KeyspM2ssCJbqUhQ4k7sveSiY4Wjn
/**
* magic-trade (Flash V2 on MagicBlock) program — the session target.
* Mainnet: FTv2RxXarPfNta45HTTMVaGvjzsGg27FXJ3hEKWBhrzV
* (verified by decoding a mainnet init-basket transaction from /v2/transaction-builder)
* (verified by decoding a mainnet init-basket transaction from /transaction-builder)
*/
/** magic-trade program (mainnet) — decoded from live builder txs. */
export const MAGIC_TRADE_PROGRAM = new PublicKey("FTv2RxXarPfNta45HTTMVaGvjzsGg27FXJ3hEKWBhrzV");
Expand Down
2 changes: 1 addition & 1 deletion examples/predict/lib/use-markets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ─────────────────────────────────────────────────────────────────────────────
// lib/use-markets.ts — live market rows for the Discover grid.
// One bulk /v2/tokens (static per session) + a polled /v2/prices; each tradeable
// One bulk /tokens (static per session) + a polled /prices; each tradeable
// token becomes a row {symbol, category, live price} the card prices into a
// YES/NO question via lib/markets.ts. Category taxonomy mirrors the picker's
// (Pyth-ticker prefix) and is HIDDEN unless most tokens classify — a partial
Expand Down
2 changes: 1 addition & 1 deletion examples/tap-trade/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ NEXT_PUBLIC_BASE_RPC=https://mainnet.helius-rpc.com/?api-key=YOUR_KEY_HERE
NEXT_PUBLIC_ER_RPC=https://flash.magicblock.xyz

# Override the hosted Flash V2 API (rarely needed).
# NEXT_PUBLIC_FLASH_API_BASE=https://flashapi.trade/v2
# NEXT_PUBLIC_FLASH_API_BASE=https://flashapi.trade
2 changes: 1 addition & 1 deletion examples/tap-trade/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function usePrice(symbol: string, intervalMs = 1000): {
}

/**
* The tradeable market list, LIVE from Flash's own config (`GET /v2/tokens` —
* The tradeable market list, LIVE from Flash's own config (`GET /tokens` —
* CDN-driven and hot-reloaded server-side): every non-stable token in the
* active pool is a market. New listings appear here automatically.
* Returns null until loaded (callers keep a static fallback meanwhile).
Expand Down
2 changes: 1 addition & 1 deletion examples/tap-trade/lib/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const SESSION_KEYS_PROGRAM = new PublicKey("KeyspM2ssCJbqUhQ4k7sveSiY4Wjn
/**
* magic-trade (Flash V2 on MagicBlock) program — the session target.
* Mainnet: FTv2RxXarPfNta45HTTMVaGvjzsGg27FXJ3hEKWBhrzV
* (verified by decoding a mainnet init-basket transaction from /v2/transaction-builder)
* (verified by decoding a mainnet init-basket transaction from /transaction-builder)
*/
/** magic-trade program (mainnet) — decoded from live builder txs. */
export const MAGIC_TRADE_PROGRAM = new PublicKey("FTv2RxXarPfNta45HTTMVaGvjzsGg27FXJ3hEKWBhrzV");
Expand Down
Loading