Skip to content

Spizzerp/flatlineOS

Repository files navigation

Flatline

Micro-leverage trading on Solana. Extreme leverage (100x–1000x) on small positions ($1–$10) with an EKG/heartbeat monitor UI and real-time price visualization.

Live at flatline.fun (devnet). Chart line visualization powered by Liveline.

How It Works

Users deposit a small amount of SOL and open leveraged positions on crypto, equities, and commodities — all settled on-chain via Pyth oracle prices. An LP pool provides the other side of every trade.

  • 100x / 500x / 1000x leverage tiers
  • 11 tradeable assets: SOL, ETH, BTC, XAU, XAG, USOIL, AAPL, TSLA, AMZN, GOOG, NVDA
  • Revenue protection: spread markup, dynamic utilization fees, funding rates, ML fee adjustor hook
  • Liquidation keeper monitors positions and auto-liquidates via Pyth prices

Architecture

┌─────────────┐     ┌──────────────┐     ┌──────────────────────┐
│   Frontend   │────▶│   Backend    │────▶│  Solana Program      │
│  (Next.js)   │     │  (Fastify)   │     │  (Anchor / Rust)     │
│              │     │              │     │                      │
│  Pyth SSE    │     │  Pyth SDK    │     │  Pyth Oracle         │
│  Zustand     │     │  Relayer     │     │  LP Pool             │
│  Wallet      │     │  Prisma      │     │  Asset Registry      │
│  Adapter     │     │  Redis       │     │  Position Mgmt       │
└─────────────┘     └──────────────┘     └──────────────────────┘
                          │
                    ┌─────┴─────┐
                    │           │
              ┌─────▼───┐ ┌────▼────┐
              │WebSocket│ │ Keeper  │
              │ Server  │ │ (Rust)  │
              └─────────┘ └─────────┘
Component Tech
Smart Contract Anchor 0.29.0, Solana 1.18.26
Oracle Pyth Network (pull oracle)
Backend Fastify, TypeScript, Prisma, Redis
Frontend Next.js 14, Tailwind CSS, Zustand
Keeper Rust, Tokio, Pyth WebSocket
WebSocket ws, Redis pub/sub

Getting Started

Prerequisites

Setup

# Clone
git clone https://github.com/spizzerp/flatlineOS.git
cd flatline

# Install dependencies
npm install
cd flatline-frontend && npm install && cd ..
cd services/backend && npm install && cd ../..

# Configure environment
cp services/backend/.env.example services/backend/.env
cp flatline-frontend/.env.example flatline-frontend/.env.local
# Edit both files with your Helius API key and RPC endpoint

# Build the program
anchor build

# Run tests (local validator)
COPYFILE_DISABLE=1 anchor test --provider.cluster localnet

Run Locally

# Terminal 1: Backend (port 3002)
cd services/backend && npm run dev

# Terminal 2: Frontend (port 3000)
cd flatline-frontend && npm run dev

# Open http://localhost:3000, connect a Solana wallet, trade

Deploy to Devnet

# Deploy program
anchor deploy --provider.cluster devnet

# Initialize protocol
ANCHOR_PROVIDER_URL=https://api.devnet.solana.com \
ANCHOR_WALLET=~/.config/solana/id.json \
npm run init

# Initialize asset registry
ANCHOR_PROVIDER_URL=https://api.devnet.solana.com \
ANCHOR_WALLET=~/.config/solana/id.json \
npx ts-node scripts/initialize-asset-registry.ts

# Add assets
ANCHOR_PROVIDER_URL=https://api.devnet.solana.com \
ANCHOR_WALLET=~/.config/solana/id.json \
npx ts-node scripts/add-asset.ts

# Fund LP pool (5 SOL)
ANCHOR_PROVIDER_URL=https://api.devnet.solana.com \
ANCHOR_WALLET=~/.config/solana/id.json \
npm run deposit-lp -- 5

Project Structure

flatline/
├── programs/flatline/       # Anchor Solana program (14 instructions)
├── flatline-frontend/       # Next.js frontend
├── services/
│   ├── backend/             # Fastify API + Pyth relayer
│   ├── websocket/           # Real-time trade event broadcast
│   └── keeper/              # Rust liquidation keeper
├── scripts/                 # Deployment & admin scripts
└── tests/                   # Anchor integration tests (32 tests)

Trading Parameters

Parameter Value
Leverage 100x, 500x, 1000x
Position sizes $1, $5, $10
Liquidation -100% PnL
Trading fee 0.25–2.0% (dynamic, utilization-based)
Spread 0.1% (configurable per asset)
Funding rate 0.1%/hr max
Fee split 70% LP / 25% Treasury / 5% Insurance

Contributing

See CONTRIBUTING.md.

Security

If you discover a security vulnerability, please see SECURITY.md for responsible disclosure instructions. Do not open a public issue.

License

MIT

About

Micro-leverage trading on Solana. 100x-1000x leverage on crypto, commodities, and equities.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages