# Usage

This guide covers running the Tycho Market Maker locally, once cloned, either directly with Rust or using Docker.

The repository is available here ⇒ <https://github.com/0xMerso/tycho-market-maker>

### Pre-requisites

* Rust Toolchain
* Redis is required for event streaming between maker and monitor.
* Postgresql is required for trade history persistence
* Node for Prisma/SeaORM (generate PGSQL structs in Rust)

<pre class="language-sh"><code class="lang-sh">curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
cargo install sea-orm-cli

<strong>## MacOS
</strong><strong>brew install redis
</strong>brew install postgresql
brew install node
## Ubuntu/Debian
sudo apt-get install redis-server
sudo apt-get install postgresql
</code></pre>

### **Build and environment Setup**

Create your configuration files (or use the quickstart) as described in the Configuration page:

* TOML file in config/ directory
* .env file in config/secrets/ directory

First build may take several minutes as Rust compiles all dependencies.

```sh
cargo build --bin maker
cargo build --bin monitor
## Release mode
cargo build --release --bin maker
cargo build --release --bin monitor
```

### PostgreSQL

<pre class="language-sh"><code class="lang-sh"><strong>## PGSQL / Prisma schema and Sea-ORM entities
</strong>sh prisma/all-in-one.sh
</code></pre>

This executes three steps:

1. Reset - Drops and recreates the database (destructive)
2. Push Schema - Applies Prisma schema to PostgreSQL
3. Generate Entities - Creates Rust structs from database tables

The sea-orm-cli creates Rust entity files in src/shd/entity/ folder

### Running Locally

#### **Option 1 - Using Shell Scripts**

```sh
## Start Market Maker 
sh ops/maker.sh mainnet.eth-usdc
```

* Loads config from config/mainnet.eth-usdc.toml
* Loads secrets from config/secrets/.env.mainnet.eth-usdc
* Builds the maker binary and run it

```sh
## Start Monitor Service
sh ops/monitor.sh
```

* Starts Redis server on port 42044
* Loads config from config/secrets/.env.monitor.global
* Builds the monitor binary
* Subscribes to Redis events and persists to PostgreSQL

Testing Mode Run with test configuration

```sh
sh ops/maker.sh --testing mainnet.eth-usdc
```

This loads from `config/testing/` instead of `config/`.

#### Option 2 - Direct Cargo Execution

```
export CONFIG_PATH="config/mainnet.eth-usdc.toml"
export SECRET_PATH="config/secrets/.env.mainnet.eth-usdc"
export RUST_LOG="off,maker=trace,shd=trace"
cargo run --bin maker
```

```
RUST_LOG="off,monitor=trace,shd=trace"
cargo run --bin monitor
```

#### Option 3 - Docker Compose

For production deployments, use Docker Compose to run multiple maker instances with monitor and Redis.

**Create Docker Network**

```bash
## Network
docker network create tmm
## Start All Services
docker compose up -d --build
```

This launches:

* Redis server on port 42044
* Monitor service (subscribes to Redis)
* Multiple maker instances, according to the docker-compose.yaml file

**Useful commands**

```sh
## View Logs
docker compose logs -f --since 5m
## Stop Services
docker compose down
## Rebuild After Code Changes
docker compose up --build
```
