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.
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 testFor 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.
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.
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.
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.
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:
JUPITER_API_KEY=...— Pro tier, enough rate for a real matrix.- Lower
MAX_VENUES— fewer venues, but valid data. - Implement the Stage 3 direct adapters — one
getMultipleAccountscall 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.
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.
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.
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.
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.
- Discovery ← you are here. Does the edge exist?
- Realistic simulation — sizes, impact, fees, latency, execution probability.
- Direct DEX integration — Raydium, Orca, Meteora. See the note above: this is a correctness prerequisite, not an optimisation.
- Shadow execution — build and simulate the real transaction; would it have landed?
- Jito + RPC optimisation — bundles, tips, landing probability.
- $50–$100 live capital — only on a meaningful sample.
- 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.
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.
MIT — see LICENSE.