# sim-cli
`sim` runs Termina simulator sessions over historical Solana slots from the command line. Replay
a slot range, swap in a new program binary or account overrides, and compare the results with
the onchain outcome or with another run.
This guide covers what each command is for. Every flag is documented in `sim <command> --help`;
guides and concepts are in the [Termina docs](https://docs.termina.technology/documentation).
## Install
```bash
mkdir -p "$HOME/.local/bin"
```
Or build it from crates.io (needs Rust 1.97 or newer):
```bash
cargo install sim-cli --locked --version 0.22.0
```
`sim update` replaces the binary with the latest prebuilt one. Prebuilt binaries track the main
branch, so pin a version with `cargo install` when you need a reproducible install.
## Commands
| `sim run` | Replay a slot range, optionally with a new program binary, account overrides or rerouted swaps, and write the results as NDJSON |
| `sim compare` | Diff two `sim run` output files: regressions, improvements, logs, compute units, balances |
| `sim summarize` | Print the totals of one output file |
| `sim ranges` | List the slot ranges the server can replay |
| `sim usage` | Show your API key's usage |
| `sim bundle` | Build, inspect and delete your custom bundles |
| `sim depth` | Request and track venue-depth datasets |
| `sim datasets credentials` | Print read-only S3 credentials for the datasets |
| `sim update` | Replace `sim` with the latest prebuilt binary |
Networked commands read your key from `SIMULATOR_API_KEY`.
## Test a new program binary
```bash
export SIMULATOR_API_KEY=<your key>
sim ranges
sim run --start-slot <start> --end-slot <end> --program-id <program> \
--output-file baseline.ndjson
sim run --start-slot <start> --end-slot <end> --program-id <program> \
--program-so ./target/deploy/program.so --output-file experiment.ndjson
sim compare baseline.ndjson experiment.ndjson
```
## Gate CI on regressions
With `--fail-on-diff`, `sim compare` exits with status 1 when the selected section has an entry:
```bash
set -e
sim compare baseline.ndjson experiment.ndjson regressions --fail-on-diff
sim compare baseline.ndjson experiment.ndjson compute-units --fail-on-diff \
--compute-units-threshold 5
```
## Reroute swaps
```bash
# Reroute the range's swaps through the router
sim run --start-slot <start> --end-slot <end> --program-id <program> --reroute-order-flow
# Price them on your own venue's instructions instead
sim run --start-slot <start> --end-slot <end> --program-id <program> \
--reroute-order-flow venue --venue-templates templates.json
```
The template format is in [File formats](https://docs.termina.technology/documentation/cli/file-formats#venue-templates).