solana-perps-funding-guard
by xgbtxy
README.md
# Solana Perps Funding Guard
[](./LICENSE)
[](./package.json)
**Live Terminal**: https://xgbtxy.github.io/solana-perps-funding-guard/
**Live Snapshot JSON**: https://xgbtxy.github.io/solana-perps-funding-guard/data/snapshot.json
**Daily Brief**: [`docs/data/daily-brief.md`](./docs/data/daily-brief.md)
Zero-dependency, read-only, keyless **pre-trade risk engine, live web terminal, and JSON-RPC 2.0 MCP server** for **Solana Perpetuals & Prediction Markets**.
It combines **Solana Mainnet-Beta L1 RPC** state verification (Jupiter Perps JLP Pool on-chain AUM + 6 custody SPL vault reserves + Jupiter/Drift program liveness), **live Solana perp DEX funding & mark-vs-index basis feeds** (Pacifica & GMX Perpetuals V2 Solana), and **live Polymarket Gamma prediction-market probabilities** to flag crowded leverage, extreme basis dislocation, and cross-market event-risk divergence before an agent or trader opens a position.
---
## Live Verified Snapshot Metrics
- **Solana Mainnet-Beta L1 Slot**: `478,308,666` (Epoch `1107`)
- **Jupiter JLP Pool On-Chain AUM**: `$587,167,895.93` (decoded directly from Anchor account bytes on `5BUwFW4nRbftYTDMbgxykoFWqWHPzahFSNAaaaJtVKsq`, 6 verified custodies + live SPL token vault balances)
- **Executable Perp Programs Verified**: Jupiter Perps (`PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu`) & Drift Protocol V2 (`dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH` + State PDA)
- **Tracked Live Solana Perp Markets**: `172` perpetual pairs across `2` Solana venues (`$179.09M` Open Interest, `$426.51M` 24h Volume)
- **Linked Live Prediction Markets**: `12` active crypto & macro Polymarket Gamma contracts
---
## Architecture
```mermaid
flowchart LR
A[Solana Mainnet L1 RPC\nJLP Pool + 6 Custodies + Programs] --> D[scripts/collect.mjs\nFail-Closed Validator + Atomic Write]
B[CoinGecko Derivatives API\nSolana Perps Funding/Basis/OI] --> D
C[Polymarket Gamma API\nActive Crypto & Macro Probabilities] --> D
D --> E[docs/data/snapshot.json\n+ daily-brief.md]
E --> F[lib/guard.mjs\nDeterministic 0-100 Risk Engine]
F --> G[mcp/server.mjs\n4-Tool JSON-RPC 2.0 Stdio MCP]
F --> H[bin/perps-guard.mjs\nZero-Dep CLI]
E --> I[docs/index.html\nDark Quant Static Terminal]
```
### Deterministic Pre-Trade Risk Scoring (`0–100`)
Every Solana perpetual market is scored transparently across 4 factors:
1. **Funding Crowding (`0–45`)**: Annualized funding APR (`8h rate × 1095`).
2. **Basis Dislocation (`0–30`)**: Mark-vs-index spread `((last - index) / index) × 100`.
3. **Liquidity & Spread Fragility (`0–15`)**: Open interest depth and bid-ask spread.
4. **Sticky Crowding Turnover (`0–10`)**: Open interest relative to 24h volume.
Verdicts: **`SAFE`** (`0–34`), **`CAUTION`** (`35–64`), **`BLOCK`** (`65–100`).
---
## Quickstart (Zero `npm install` Required)
Requires **Node.js 20+**.
```bash
# 1. Refresh live Solana L1 + Perps + Polymarket snapshot
npm run collect
# 2. Run syntax checks & 17 unit + MCP E2E tests
npm run check
npm test
# 3. CLI pre-trade checks
node bin/perps-guard.mjs audit SOL --side LONG
node bin/perps-guard.mjs alerts --limit 10 --min-oi 10000
node bin/perps-guard.mjs hedge BTC
node bin/perps-guard.mjs health
```
---
## MCP Server Integration (4 Keyless Read-Only Tools)
Add to Claude Desktop, Cursor, or any MCP stdio client:
```json
{
"mcpServers": {
"solana-perps-funding-guard": {
"command": "node",
"args": ["mcp/server.mjs"]
}
}
}
```
| Tool | Purpose |
|---|---|
| `audit_solana_perp_market` | Audit funding APR, basis %, OI, risk score (0–100), `SAFE/CAUTION/BLOCK` & LONG/SHORT side guidance |
| `list_extreme_funding_alerts` | Rank top Solana perp contracts by squeeze risk, funding APR, or basis dislocation |
| `compare_prediction_hedge` | Detect cross-market event-risk divergence between Solana perps and live Polymarket probabilities |
| `get_solana_perps_snapshot_health` | Return live Solana Mainnet L1 slot, JLP Pool AUM, program liveness, and snapshot freshness age |
---
## On-Chain Decode Honesty & Fail-Closed Design
- Jupiter JLP Pool (`5BUwFW4nRbftYTDMbgxykoFWqWHPzahFSNAaaaJtVKsq`) and its 6 Custody accounts are decoded directly from verified Solana Mainnet account offsets (`name`, `custodies`, `aum_usd`, `mint`, `decimals`, `is_stable`, and SPL Token Account `amount` at byte 64). Internal fee/borrowing curves are intentionally left undecoded rather than guessed.
- `validateSnapshot()` runs fail-closed before any atomic write: if RPC slot `<= 0` or live markets are empty, the collector exits non-zero and preserves the last known good snapshot.
## License
MIT © 2026 xgbtxy
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues