Skip to content
Abhist17Public

About

Solana cross-venue arbitrage detector

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

sol-arb - Solana cross-venue arbitrage research

Stage 1 (Discovery). Detects and logs only. No wallet, no keys, no execution path.

The question this answers is not "can I write an arb bot" but "does an edge exist for someone at my capital and latency" — and if not, which part of the system is the reason. It is built to be able to return "no", and the reporting is designed so that a "no" is legible rather than silent.

Quick start

npm install
npm run collect        # Ctrl-C to stop; writes data/arbitrage.db
npm run report 24      # the go/no-go dashboard, last 24h
npm run sizing 24      # where price impact overtakes spread
npm test

What it actually measures

For each (pair, size) it collects a venue-pinned price matrix: what each individual DEX will pay for each leg, quoted through Jupiter with dexes= set to a single label. It then scores every buy-venue × sell-venue pairing through the full cost stack and an expected-value model, and writes all of them — winners and losers — to SQLite.

Why not a plain A→B→A round trip. Jupiter's router already arbitrages across venues internally, so an unpinned round trip returns the post-arbitrage price. It will show ~0% gross by construction, and finding nothing would tell you nothing. Pinning each leg to one venue recovers the per-venue price, and the spread between two pinned venues is the signal.

The cost stack

gross from the router is already net of DEX fees and price impact, so those are reported for attribution rather than subtracted twice. What comes off on top: base tx fee, priority fee, Jito tip, and an execution buffer for model uncertainty. Two figures come out — netUsd on expected fills, and netWorstCaseUsd on both legs' slippage bounds. The executability gate reads the worst case, because an edge that only clears on the optimistic path is not an edge.

Expected value, not "the quote looks profitable"

EV = P(success) × net − (1 − P(success)) × lossOnFail

P(success) comes from a transparent logistic model in src/arbitrage/opportunity-score.ts. Every coefficient is a documented prior, not a fitted value — treat it as an ordering signal between opportunities, not a calibrated probability, until Stage 4 supplies realised outcomes to fit against. The signs encode defensible beliefs: notably that wider spreads lower the win probability, because a large visible gap is a crowded race.

lossOnFail is fee-dominated by design, because the builder is required to attach a profit-assert instruction that reverts unless the trade ends ahead. If that assert is ever dropped, adverseFillBps must rise sharply — a failure would then leave an unhedged position rather than costing fees.

Opportunity lifetime

The most decision-relevant number Stage 1 can produce without capital. A 30bps spread that dies in 80ms is not addressable by Node talking to a public RPC; the same spread living 600ms is. Measured by re-quoting the winning pairing until it stops clearing the threshold. Measurements are right-censored — an edge still alive at the last probe is flagged, and must be read as a lower bound.

Known constraint: the free Jupiter tier cannot produce valid data

Measured against the live API, not assumed:

free (lite-api) pro (JUPITER_API_KEY)
sustained rate ~0.7 req/s ~10 req/s
15 back-to-back requests 15 × HTTP 429 fine

A matrix over N venues costs 2N requests. At 0.7 req/s, even 3 venues takes ~7s — during which Solana produces ~18 slots. The two legs of every pairing were then priced seconds apart, so any spread between them is an artefact of time passing rather than an arbitrage. The detector rejects exactly this on slot_skew.

src/preflight.ts checks this at startup and refuses to run, rather than letting you collect a fortnight of empty results that look like an absent edge but are really a measurement failure. Options it offers, best first:

  1. JUPITER_API_KEY=... — Pro tier, enough rate for a real matrix.
  2. Lower MAX_VENUES — fewer venues, but valid data.
  3. Implement the Stage 3 direct adapters — one getMultipleAccounts call reads every pool at a single slot, making the matrix skew-free by construction.

IGNORE_PREFLIGHT=1 overrides it. The rows are not evidence.

This reframes Stage 3 (direct DEX integration): it is not a latency optimisation, it is a prerequisite for a valid measurement. Only direct account reads give a consistent-slot snapshot across venues.

Layout

src/
  market/      venue adapters — jupiter.ts is live; raydium/orca/meteora are Stage 3
  quotes/      collection, normalisation, freshness (age + slot skew)
  arbitrage/   pairing enumeration, cost stack, EV scoring, detector
  execution/   simulator.ts (lifetime, live) — builder/executor/jito are Stage 4-6
  risk/        limits, circuit breaker, position sizing
  rpc/         multi-endpoint health and failover (Stage 3 load-bearing)
  analytics/   metrics, paper P&L, the report
  db/          SQLite schema and store

Unimplemented stages throw NotImplementedYet with the stage named. The interfaces are fixed now so the detection path is written against them, but the transaction-building code is deliberately absent — writing it before the lifetime data justifies going live is how you end up with a wallet-enabled binary and no evidence.

The circuit breaker runs in Stage 1

It gates nothing yet — nothing trades — but it observes every cycle from day one, so its rules meet real market conditions and its false-positive rate becomes measurable before capital is exposed. A breaker first switched on the day you go live is an untested breaker. Tripping is one-way; recovery is a human decision.

It already fires in practice: a free-tier run trips quote_age within minutes, which is the correct response to 7-second-old prices.

Configuration

All via environment variables (see src/config.ts):

var default purpose
JUPITER_API_KEY — switches to the Pro host and raises the rate limit
RATE_LIMIT_RPS 0.7 / 10 sustained request rate
MAX_VENUES 4 / 10 venues per leg; each costs 2 requests
CYCLE_INTERVAL_MS 5000 pause between cycles
IGNORE_PREFLIGHT 0 collect despite invalid-by-construction data
DB_PATH data/arbitrage.db
LOG_LEVEL info

Trade sizes, pairs, venues and the whole cost model live in src/config.ts.

Reading the verdict

The report refuses to give a green light on under 24h of data, on non-positive EV, or on under $1/day (below the cost model's own noise floor, so the sign is not trustworthy). Even a pass points at Stage 4 shadow execution, not live capital: everything here still assumes fills that have never been tested against a real block.

Roadmap

  1. Discovery ← you are here. Does the edge exist?
  2. Realistic simulation — sizes, impact, fees, latency, execution probability.
  3. Direct DEX integration — Raydium, Orca, Meteora. See the note above: this is a correctness prerequisite, not an optimisation.
  4. Shadow execution — build and simulate the real transaction; would it have landed?
  5. Jito + RPC optimisation — bundles, tips, landing probability.
  6. $50–$100 live capital — only on a meaningful sample.
  7. Scale — only when realised P&L, model agreement, and risk limits all hold.

Sandwich/backrun strategies are deliberately out of scope. Build clean arbitrage first.

Disclaimer

Research code. It detects and logs; it does not trade, hold keys, or sign anything, and the execution path is deliberately unimplemented.

Nothing here is financial advice. The cost model, the execution-probability priors, and the venue list are assumptions, not measurements — they are starting points to be replaced with fitted values once the data exists. Do not put capital behind any number this produces without understanding how it was derived and validating it yourself.

License

MIT — see LICENSE.

About

Solana cross-venue arbitrage detector

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages