# focus1010/solana-smart-tx-stack architecture

> Architecture diagram of the GitHub repository focus1010/solana-smart-tx-stack, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/focus1010/solana-smart-tx-stack
- Repository: https://github.com/focus1010/solana-smart-tx-stack

## Overview

#### Purpose and Entry Points
This is a TypeScript/Node.js Solana transaction-infrastructure stack for submitting Jito bundles, monitoring their lifecycle, and producing auditable run evidence. The main batch-run entry point is `src/index.ts`, which initializes the orchestrator in `src/stack.ts`. Reactive submission modes are driven by `src/scripts/run-marinade.ts` and stream trigger modules.

#### Orchestration and Shared Contract
`Stack` coordinates observation, AI decisioning, bundle construction, submission, tracking, failure recovery, and lifecycle persistence. Shared domain records—including network snapshots, decisions, failures, and lifecycle entries—cross subsystem boundaries through `src/types.ts`; runtime configuration and safety limits originate in `src/config.ts`.
- `src/stack.ts`
- `src/types.ts`
- `src/config.ts`

#### Network Observation Layer
The stack is stream-first. `SlotStream` consumes Yellowstone Geyser slot events, maintains separate processed/confirmed/finalized progress, reconnects with replay/backpressure support, and falls back to RPC polling if the stream is unavailable. `NetworkStateObserver` derives current congestion and confirmation metrics, while `TipOracle` obtains Jito auction tip-floor data with Solana priority-fee fallback.
- `src/stream/slot-stream.ts`
- `src/geyser/reconnecting-stream.ts`
- `src/stream/network-state-observer.ts`
- `src/stream/tip-oracle.ts`

#### Jito Routing and Bundle Construction
Before submission, leader-window detection determines whether a Jito-connected leader is near. The builder obtains a confirmed-commitment blockhash via its cache, applies hard tip bounds, constructs the Jito bundle and tip instruction, and passes it to the selected Jito transport (JSON-RPC or gRPC). Mainnet submission is leader-window gated unless explicitly overridden.
- `src/jito/leader-window-detector.ts`
- `src/bundle/bundle-builder.ts`
- `src/bundle/bundle-submitter.ts`
- `src/jito/create-jito-client.ts`

#### AI Decision and Guardrail Boundary
The agent receives a complete network snapshot and decides the tip and, after failure, retry behavior. Provider selection is isolated behind an LLM abstraction: Groq/Llama is primary and Anthropic is optional. Model outputs are not authoritative: stack/builder guardrails clamp tips and prohibit retries for non-recoverable classes such as compute or simulation failures.
- `src/agent/agent.ts`
- `src/agent/llm-provider.ts`
- `src/agent/provider-factory.ts`
- `src/bundle/failure-classifier.ts`

#### Submission Lifecycle and Recovery
A real Solana transaction is also sent for independently verifiable on-chain signature tracking; the Jito bundle is submitted to the block engine. `CommitmentTracker` resolves processed, confirmed, and finalized stages from Yellowstone events first, with RPC signature-status fallback on timeout. `LifecycleTracker` records timestamps, source attribution, raw bundle outcomes, decision reasoning, snapshots, and classified failures; retries re-enter the agent-driven orchestration loop with refreshed blockhashes when selected.
- `src/lifecycle/commitment-tracker.ts`
- `src/lifecycle/lifecycle-tracker.ts`
- `src/bundle/failure-classifier.ts`
- `logs/lifecycle.json`

#### Reactive Triggering and Interfaces
Besides fixed-count batch execution, protocol event streams can initiate submissions: Marinade staking activity and USDC/Raydium triggers feed into the same `Stack` execution path. A local HTTP dashboard reads lifecycle records and presents aggregated status through a static frontend.
- `src/stream/marinade-event-stream.ts`
- `src/stream/protocol-trigger.ts`
- `src/dashboard/server.ts`
- `web/dashboard/index.html`

#### Runtime and External Dependencies
The runtime is Node.js 20.11+ with strict TypeScript. Material external boundaries are Solana RPC/WebSocket endpoints (a dedicated provider such as Helius is recommended), Yellowstone gRPC, Jito Block Engine and tip-floor API, Groq or Anthropic APIs, and a wallet private key. Lifecycle logs are the durable local audit boundary; evidence artifacts are generated from them under `evidence/`.

Main entry points: [`src/stack.ts`](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/stack.ts) (Stack orchestrator), [`src/bundle/bundle-submitter.ts`](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/bundle/bundle-submitter.ts) (Bundle submitter), [`src/stream/slot-stream.ts`](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/stream/slot-stream.ts) (SlotStream), [`src/agent/agent.ts`](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/agent/agent.ts) (AI agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_batch_entry["Batch entry<br/>Node entry point<br/>[index.ts]"]
  node_stack["Stack orchestrator<br/>orchestration<br/>[stack.ts]"]
  node_contracts["Domain contracts<br/>shared types<br/>[types.ts]"]
  node_config["Safety configuration<br/>runtime config<br/>[config.ts]"]
end

subgraph group_observation["Network observation"]
  node_slot_stream["SlotStream<br/>slot progress stream<br/>[slot-stream.ts]"]
  node_geyser["Reconnecting Geyser<br/>Yellowstone transport"]
  node_network_observer["Network state observer<br/>metrics derivation"]
  node_tip_oracle["Tip oracle<br/>fee source<br/>[tip-oracle.ts]"]
end

subgraph group_decision["Decision &amp; bundle"]
  node_agent["AI agent<br/>tip and retry decision<br/>[agent.ts]"]
  node_provider_factory["LLM providers<br/>provider abstraction"]
  node_leader_window["Leader-window detector<br/>Jito eligibility"]
  node_bundle_builder["Bundle builder<br/>transaction construction<br/>[bundle-builder.ts]"]
  node_bundle_submitter["Bundle submitter<br/>Jito submission"]
  node_jito_client["Jito client<br/>JSON-RPC / gRPC transport"]
  node_failure_classifier["Failure classifier<br/>retry guardrail"]
end

subgraph group_lifecycle["Lifecycle &amp; audit"]
  node_commitment_tracker["Commitment tracker<br/>signature tracking"]
  node_lifecycle_tracker["Lifecycle tracker<br/>audit persistence"]
  node_lifecycle_log[("Lifecycle log<br/>durable audit store<br/>[lifecycle.json]")]
end

subgraph group_interfaces["Triggers &amp; dashboard"]
  node_marinade_stream["Marinade event stream<br/>reactive trigger"]
  node_protocol_trigger["Protocol triggers<br/>reactive trigger"]
  node_dashboard["Local dashboard<br/>HTTP status interface<br/>[server.ts]"]
  node_dashboard_ui["Dashboard frontend<br/>static frontend<br/>[index.html]"]
end

node_batch_entry -->|"initializes"| node_stack
node_marinade_stream -->|"triggers"| node_stack
node_protocol_trigger -->|"triggers"| node_stack
node_config -->|"limits"| node_stack
node_contracts -.->|"shared records"| node_stack
node_geyser -->|"slot events"| node_slot_stream
node_slot_stream -->|"progress"| node_network_observer
node_slot_stream -->|"commitment events"| node_commitment_tracker
node_network_observer -->|"network snapshot"| node_stack
node_tip_oracle -->|"tip floor"| node_stack
node_stack -->|"requests decision"| node_agent
node_provider_factory -->|"model provider"| node_agent
node_agent -->|"tip decision"| node_bundle_builder
node_leader_window -->|"submission gate"| node_bundle_submitter
node_bundle_builder -->|"bundle and transaction"| node_bundle_submitter
node_bundle_submitter -->|"submits bundle"| node_jito_client
node_bundle_submitter -->|"signature"| node_commitment_tracker
node_commitment_tracker -->|"commitment stages"| node_lifecycle_tracker
node_failure_classifier -->|"retry eligibility"| node_stack
node_lifecycle_tracker -->|"persists evidence"| node_lifecycle_log
node_lifecycle_log -->|"reads records"| node_dashboard
node_dashboard -->|"serves"| node_dashboard_ui

click node_batch_entry "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/index.ts"
click node_stack "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/stack.ts"
click node_contracts "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/types.ts"
click node_config "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/config.ts"
click node_slot_stream "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/stream/slot-stream.ts"
click node_geyser "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/geyser/reconnecting-stream.ts"
click node_network_observer "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/stream/network-state-observer.ts"
click node_tip_oracle "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/stream/tip-oracle.ts"
click node_agent "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/agent/agent.ts"
click node_provider_factory "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/agent/provider-factory.ts"
click node_leader_window "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/jito/leader-window-detector.ts"
click node_bundle_builder "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/bundle/bundle-builder.ts"
click node_bundle_submitter "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/bundle/bundle-submitter.ts"
click node_jito_client "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/jito/create-jito-client.ts"
click node_failure_classifier "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/bundle/failure-classifier.ts"
click node_commitment_tracker "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/lifecycle/commitment-tracker.ts"
click node_lifecycle_tracker "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/lifecycle/lifecycle-tracker.ts"
click node_lifecycle_log "https://github.com/focus1010/solana-smart-tx-stack/blob/main/logs/lifecycle.json"
click node_marinade_stream "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/stream/marinade-event-stream.ts"
click node_protocol_trigger "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/stream/protocol-trigger.ts"
click node_dashboard "https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/dashboard/server.ts"
click node_dashboard_ui "https://github.com/focus1010/solana-smart-tx-stack/blob/main/web/dashboard/index.html"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_batch_entry,node_stack,node_contracts,node_config toneBlue
class node_slot_stream,node_geyser,node_network_observer,node_tip_oracle toneAmber
class node_agent,node_provider_factory,node_leader_window,node_bundle_builder,node_bundle_submitter,node_jito_client,node_failure_classifier toneMint
class node_commitment_tracker,node_lifecycle_tracker,node_lifecycle_log toneRose
class node_marinade_stream,node_protocol_trigger,node_dashboard,node_dashboard_ui toneIndigo
```

## Components

### Runtime

- [Batch entry](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/index.ts): Node entry point · `src/index.ts`
- [Stack orchestrator](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/stack.ts): orchestration · Coordinates decisioning, submission, tracking, recovery, and persistence. · `src/stack.ts`
- [Domain contracts](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/types.ts): shared types · Snapshots, decisions, failures, and lifecycle records. · `src/types.ts`
- [Safety configuration](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/config.ts): runtime config · `src/config.ts`

### Network observation

- [SlotStream](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/stream/slot-stream.ts): slot progress stream · Tracks processed, confirmed, and finalized slots with RPC fallback. · `src/stream/slot-stream.ts`
- [Reconnecting Geyser](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/geyser/reconnecting-stream.ts): Yellowstone transport · Reconnects with replay and backpressure support. · `src/geyser/reconnecting-stream.ts`
- [Network state observer](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/stream/network-state-observer.ts): metrics derivation · `src/stream/network-state-observer.ts`
- [Tip oracle](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/stream/tip-oracle.ts): fee source · Uses Jito tip floors with priority-fee fallback. · `src/stream/tip-oracle.ts`

### Decision & bundle

- [AI agent](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/agent/agent.ts): tip and retry decision · Decides tips and retry behavior from network snapshots. · `src/agent/agent.ts`
- [LLM providers](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/agent/provider-factory.ts): provider abstraction · Selects Groq/Llama or optional Anthropic. · `src/agent/provider-factory.ts`
- [Leader-window detector](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/jito/leader-window-detector.ts): Jito eligibility · `src/jito/leader-window-detector.ts`
- [Bundle builder](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/bundle/bundle-builder.ts): transaction construction · Caches confirmed blockhashes and enforces hard tip bounds. · `src/bundle/bundle-builder.ts`
- [Bundle submitter](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/bundle/bundle-submitter.ts): Jito submission · `src/bundle/bundle-submitter.ts`
- [Jito client](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/jito/create-jito-client.ts): JSON-RPC / gRPC transport · `src/jito/create-jito-client.ts`
- [Failure classifier](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/bundle/failure-classifier.ts): retry guardrail · Blocks retries for non-recoverable compute or simulation failures. · `src/bundle/failure-classifier.ts`

### Lifecycle & audit

- [Commitment tracker](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/lifecycle/commitment-tracker.ts): signature tracking · Uses Yellowstone events first and RPC status on timeout. · `src/lifecycle/commitment-tracker.ts`
- [Lifecycle tracker](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/lifecycle/lifecycle-tracker.ts): audit persistence · Captures outcomes, reasoning, snapshots, and failures. · `src/lifecycle/lifecycle-tracker.ts`
- [Lifecycle log](https://github.com/focus1010/solana-smart-tx-stack/blob/main/logs/lifecycle.json): durable audit store · `logs/lifecycle.json`

### Triggers & dashboard

- [Marinade event stream](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/stream/marinade-event-stream.ts): reactive trigger · `src/stream/marinade-event-stream.ts`
- [Protocol triggers](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/stream/protocol-trigger.ts): reactive trigger · USDC/Raydium activity initiates stack execution. · `src/stream/protocol-trigger.ts`
- [Local dashboard](https://github.com/focus1010/solana-smart-tx-stack/blob/main/src/dashboard/server.ts): HTTP status interface · Aggregates lifecycle records for the static frontend. · `src/dashboard/server.ts`
- [Dashboard frontend](https://github.com/focus1010/solana-smart-tx-stack/blob/main/web/dashboard/index.html): static frontend · `web/dashboard/index.html`

## Connections

- Batch entry → Stack orchestrator: initializes
- Marinade event stream → Stack orchestrator: triggers
- Protocol triggers → Stack orchestrator: triggers
- Safety configuration → Stack orchestrator: limits
- Domain contracts → Stack orchestrator: shared records
- Reconnecting Geyser → SlotStream: slot events
- SlotStream → Network state observer: progress
- SlotStream → Commitment tracker: commitment events
- Network state observer → Stack orchestrator: network snapshot
- Tip oracle → Stack orchestrator: tip floor
- Stack orchestrator → AI agent: requests decision
- LLM providers → AI agent: model provider
- AI agent → Bundle builder: tip decision
- Leader-window detector → Bundle submitter: submission gate
- Bundle builder → Bundle submitter: bundle and transaction
- Bundle submitter → Jito client: submits bundle
- Bundle submitter → Commitment tracker: signature
- Commitment tracker → Lifecycle tracker: commitment stages
- Failure classifier → Stack orchestrator: retry eligibility
- Lifecycle tracker → Lifecycle log: persists evidence
- Lifecycle log → Local dashboard: reads records
- Local dashboard → Dashboard frontend: serves
