Solver in 20 minutes
Upcoming · The si-solver CLI and MockRelay are the next solver SDK release. The devnet path below works today.
The 20-minute path (upcoming)
Section titled “The 20-minute path (upcoming)”npx si-solver dev
si-solver dev will run an inventory solver against MockRelay with a stub pricer and print each request, quote and fill. --webhook URL prices through your own endpoint, in any language; --devnet points it at a running devnet stack instead. Two more commands:
npx si-solver gate-checkreplays a batch of requests and prints the admission checks of the solver programme in the programme's words. The 48-hour dry run is the one check it cannot simulate, and it will say so.npx si-solver keysmakes a quote-signing key and prints the registration payload.
In code:
import { serveRelay, MockRelay, webhookPricer } from '@fondaco/solver-sdk';
const relay = new MockRelay({ flow: 'steady' }); // in-process Relay 1.0
await serveRelay({ relay, pricer: webhookPricer('http://localhost:8080/price'), inventory: { NIGHT: 10_000n } });
MockRelay will speak the solver WebSocket protocol in process, check every quote's signature and terms as the relay does, and report what the programme's gate would see: response times, signature failures, would-win rate and fades. It will use mock proofs and a mock chain; see What is mocked.
What works today: a solver on the local devnet
Section titled “What works today: a solver on the local devnet”Everything a third-party solver needs is in @si/solver-sdk today, and our own solver is built only on it (a test fails if it imports anything else). So the fastest real start is to run a copy of our solver under your own id, then replace its pricing.
1. Start the stack. Follow steps 1 and 2 of the wallet quickstart: npm ci && npm run build, then scripts/stack.sh up. The relay listens on http://localhost:4000 and the devnet on :7300.
2. Register your solver. On the devnet the operator's admin API is open to the seed script. This registers my-solver under an existing devnet entity, with a devnet bond, in dry run:
SOLVERS=my-solver:rfq:agent-co:20000 node scripts/seed-programme.mjs
Its quote key and bearer token are derived from public labels (si:quote-key:my-solver, devnet-token-my-solver), which the SDK allows only while the relay is on loopback. Off loopback, every secret must be given.
3. Run it.
SOLVER_ID=my-solver HTTP_PORT=7440 STATE_DIR=.stack/my-solver node apps/solver/dist/src/main.js
On loopback, without RELAY_PUBLIC_KEY, it pins the key in the relay's first welcome for the life of the process; off loopback the key is required and the relay URL must be https://. GET http://127.0.0.1:7440/status shows what it is doing; /inventory shows its NIGHT. Requests reach it once it is connected; admit it with node scripts/seed-programme.mjs --admit after its dry run, or start the stack with AUTO_ADMIT=true.
4. Price it your way. The solver prices from the relay's reference mid with a spread and an inventory skew (SPREAD_BPS, SKEW_MAX_BPS; every setting is in the solver README). To price from your own system, give serveRelay a pricer. webhookPricer posts each request to your endpoint, in any language:
import { serveRelay, webhookPricer, midBound } from '@si/solver-sdk'; // @fondaco/solver-sdk once published
// The most the SDK will sign for, whatever the webhook answers: what the relay's reference
// mid pays plus a tolerance, capped by what you hold. `refPrice` is a RefPrice reading the
// relay's mid; USDM and NIGHT are the token ids the relay's /network lists.
const bound = midBound(refPrice, { usdm: USDM, night: NIGHT }, {
toleranceBps: 50,
available: (token) => myInventory(token),
});
serveRelay(solver, client, { price: webhookPricer('http://localhost:8080/price', { bound }) });
Your endpoint receives { requestId, pair, giveAmount, minWantAmount, feeDecl, notional, settlements } as JSON and answers { "wantAmount": "<integer string>" } to quote or { "decline": true } to pass. It has 250 ms by default (timeoutMs); a slow or malformed answer is no quote. The minimal solver in the SDK README shows the rest of the wiring: connectChain, MakerSolver and RelayClient.
What the SDK does for you, and what you bring
Section titled “What the SDK does for you, and what you bring”The SDK signs quotes and ladders, checks every accept and job against the quote it signed and acts on each once, builds and proves your leg, merges, sponsors DUST within your cap, keeps a DUST-generating NIGHT reserve it never spends, and refuses a reference mid outside your band. You bring inventory, pricing and strategy.
Your leg is public where it is NIGHT
Section titled “Your leg is public where it is NIGHT”When you sell NIGHT, your NIGHT input is public on chain, as the user's NIGHT output is; the USDM side stays hidden. A winning solver learns the user's receiver address, because it pays out to it, and nothing about who asked. The threat model has the full table.
- Preprod. The same solver on Preprod needs proven legs, a funded wallet and a token from us: docs/PREPROD.md and the
INDEXER_*,NODE_URLsettings in the solver README. - The rules. Bond, quote limits, the dry run, fade penalties and the reputation record: the solver programme; on the public site, for solvers.
- The messages you sign. Quotes, ladders and the fee declaration: the RFQ envelope.