Skip to content

System overview

Four repositories, one backend, three on-chain vault contracts, and a per-chain settlement relayer. This page is the map; the rest of the section is the territory.

The whole system on one page

Per-layer detail is in the pages linked at the bottom of this page; the two request paths that matter most are drawn out in quote → settle pipeline and chat request path.

Layer responsibilities

LayerOwnsDeliberately does not own
defi-dexRendering, wallet interaction, streaming consumption, route preselectionInterpreting free text, choosing a route, holding secrets
bz-agentIntent classification, parameter extraction, conversational answersChain access, execution, token resolution
bz-backendQuote fan-out, provider secrets, route building, EIP-712 signing, automation crons, all persistence, the ecosystem layerDeciding what a sentence means
swap-sdkOne class per aggregator, relayer meta-transaction assembly, chain and address constantsAPI keys (injected via configure), business rules
ContractsSettlement, custody guarantees, spending limitsRoute selection, pricing

Four things worth understanding first

1. The frontend consumes swap-sdk too

swap-sdk is not a server-only library. defi-dex/src/utils/trade.ts wraps it, and the frontend uses RelayerFactory directly to build and send the settlement transaction with the user's BrowserProvider.

The practical consequence: an SDK version bump is a coordinated release across two consumers. Both bz-backend/package.json and defi-dex/package.json pin github:blazpay/swap-sdk#vX.Y.Z, and they can drift. At the time of writing the backend is on v1.12.0 and the frontend has lagged in the past.

2. Quoting is two round-trips, on purpose

Provider APIs separate quoting from transaction building, and raw provider responses are too large to ship to a browser. So:

  1. GET /defi/quotes (SSE) streams small meta objects and caches the full { data, meta, restProps } in Redis under meta.id for five minutes.
  2. GET /defi/swap/:id rehydrates that and calls the provider's build endpoint.

This is why a quote expires, and why the confirm screen can fail after a long pause.

3. Automation and interactive trading share the routing layer but not the settlement contract

PathSettles through
Interactive swap / bridgeBlazpayRelayer
CSIP scheduled buyDCA vault's own batchExecuteDeposit
Autopilot tradeAutopilot vault's own executeTrade / batchExecuteTrades

All three ask swap-sdk for a route. Only the first goes through the relayer. That is why the vaults have their own minOut and measured-delta logic — they cannot rely on the relayer's protections.

4. Nothing in the chat path can spend money on its own

The agent produces an intent object. The backend re-resolves every parameter against real Network and Token records and real provider quotes. The user signs. A prompt injection can at worst produce a wrong intent object, which then fails resolution or produces a card the user declines.

Request-path summaries

Interactive swapdefi-dex → SSE /defi/quotesswap.serviceswap-sdk fan-out → Redis cache → user picks → /defi/swap/:id build → /defi/sign EIP-712 → user sends executeMetaTransactionSwap. Detail: quote → settle pipeline.

Chat messagedefi-dex → SSE /v1/blaz/message/streamblaz.controller persists → agent.servicebz-agent /chat/:sessionId → LangGraph → intent + params → handler executes → { text, data, action } → SSE meta/token/doneBotMessage renders. Detail: chat request path.

Scheduled buydcaCron tick → read due positions → executionEngine quotes top 3 candidates → probe each with estimateGasbatchExecuteDeposit → vault credits measured delta → processAutoClaims. Detail: execution engine.

Autopilot tradeautopilotCron tick → sync on-chain state → autopilotEngine evaluates triggers against the Redis price series → RugCheck safety gate → executionEngine route + probe → batchExecuteTrades → measured delta minus 20 bps. Detail: policy engine.

Where to go next

If you are working on…Read
Adding or debugging a liquidity providerswap-sdk internals, add a provider
A settlement bug or a fee questionBlazpayRelayer
Solana or TRONnon-EVM paths
CSIP or Autopilot executionexecution engine
An Autopilot policy or triggerpolicy engine
A new AI capabilityagent graph, add an intent
Chat renderingaction renderer
A schema or query questiondata model
Bundle size, routing, or the two shellsfrontend architecture
Landing pages, sitemaps, crawlersSEO subsystem
A threat-model questionsecurity model
Hosts, ports, processesruntime topology

Internal + developer documentation. Usage figures are point-in-time snapshots — re-verify before publishing them.