|
| 1 | +# Omni Relayer |
| 2 | + |
| 3 | +Off-chain component of [Omni Bridge](https://github.com/near-one/omni-bridge) that relays transfers between NEAR and other networks (Ethereum, Solana, BTC, and more). |
| 4 | + |
| 5 | +## Deployment |
| 6 | + |
| 7 | +Docker Compose is the recommended way to deploy the relayer. It bundles the relayer with NATS (message queue) and Redis (state store), and automatically creates the required JetStream streams. |
| 8 | + |
| 9 | +### 1. Configure secrets |
| 10 | + |
| 11 | +```bash |
| 12 | +cp .example-env .env |
| 13 | +``` |
| 14 | + |
| 15 | +Edit `.env` and fill in your credentials: |
| 16 | + |
| 17 | +| Variable | Required | Description | |
| 18 | +|----------|----------|-------------| |
| 19 | +| `NEAR_OMNI_ACCOUNT_ID` / `NEAR_OMNI_PRIVATE_KEY` | Yes | NEAR account for signing relay transactions | |
| 20 | +| `ETH_PRIVATE_KEY`, `BASE_PRIVATE_KEY`, ... | Per chain | EVM chain private keys (only for chains you enable) | |
| 21 | +| `SOLANA_PRIVATE_KEY` | If Solana enabled | Solana keypair (bs58-encoded) | |
| 22 | +| `INFURA_API_KEY` | If using Infura | API key for EVM RPC endpoints | |
| 23 | +| `MONGODB_USERNAME` / `MONGODB_PASSWORD` / `MONGODB_HOST` | If using bridge indexer | Bridge indexer database credentials | |
| 24 | +| `BRIDGE_NATS_USERNAME` / `BRIDGE_NATS_PASSWORD` | Yes | NATS authentication credentials | |
| 25 | + |
| 26 | +### 2. Configure the relayer |
| 27 | + |
| 28 | +```bash |
| 29 | +cp example-docker-config.toml config.toml |
| 30 | +``` |
| 31 | + |
| 32 | +Edit `config.toml`: |
| 33 | +- **Enable only the chains you want to relay** — comment out or remove sections for chains you don't support |
| 34 | +- **Set your RPC endpoints** — replace Infura URLs with your own providers if preferred |
| 35 | +- **Adjust fee settings** — `fee_discount` in `[bridge_indexer]` controls how much discount you accept (0-100) |
| 36 | +- **Token whitelist** (optional) — restrict to specific tokens via `whitelisted_tokens` |
| 37 | + |
| 38 | +### 3. Set NATS credentials |
| 39 | + |
| 40 | +The included `nats.conf` reads credentials from environment variables passed by docker-compose. Set `BRIDGE_NATS_USERNAME` and `BRIDGE_NATS_PASSWORD` in your `.env` file — these are used for both the NATS server and the relayer connection. |
| 41 | + |
| 42 | +### 4. SSH access for build |
| 43 | + |
| 44 | +The build fetches private GitHub dependencies via SSH. Make sure your SSH agent has a key with access to `github.com/near-one`: |
| 45 | + |
| 46 | +```bash |
| 47 | +ssh-add -l # check loaded keys |
| 48 | +ssh-add ~/.ssh/id_ed25519 # add if needed |
| 49 | +ssh -T git@github.com # verify access |
| 50 | +``` |
| 51 | + |
| 52 | +### 5. Deploy |
| 53 | + |
| 54 | +```bash |
| 55 | +docker compose up -d |
| 56 | +``` |
| 57 | + |
| 58 | +This starts: |
| 59 | +- **NATS** — JetStream message queue |
| 60 | +- **nats-init** — creates `OMNI_EVENTS` and `RELAYER` streams (runs once, idempotent) |
| 61 | +- **Redis** — state and checkpoint storage |
| 62 | +- **relayer** — the omni-relayer process |
| 63 | + |
| 64 | +All services are configured with `restart: unless-stopped` for automatic recovery. |
| 65 | + |
| 66 | +### Verify |
| 67 | + |
| 68 | +```bash |
| 69 | +# Check all services are running |
| 70 | +docker compose ps |
| 71 | + |
| 72 | +# View relayer logs |
| 73 | +docker compose logs -f relayer |
| 74 | + |
| 75 | +# Check NATS streams were created |
| 76 | +docker compose logs nats-init |
| 77 | +``` |
| 78 | + |
| 79 | +### Update |
| 80 | + |
| 81 | +```bash |
| 82 | +git pull |
| 83 | +docker compose up -d --build |
| 84 | +``` |
| 85 | + |
| 86 | +## Configuration Reference |
| 87 | + |
| 88 | +The relayer is configured through a TOML file with environment variable substitution at parse time (variables like `INFURA_API_KEY` in RPC URLs are replaced automatically from the environment). |
| 89 | + |
| 90 | +Example configs: |
| 91 | +- `example-docker-config.toml` — docker-compose deployment (recommended starting point) |
| 92 | +- `example-devnet-config.toml` — devnet/testnet with all chains |
| 93 | +- `example-testnet-config.toml` — testnet |
| 94 | +- `example-mainnet-config.toml` — mainnet |
| 95 | + |
| 96 | +| Section | Purpose | |
| 97 | +|---------|---------| |
| 98 | +| `[redis]` | Connection URL and retry settings | |
| 99 | +| `[nats]` | Connection URL, consumer names, retry backoff, worker count | |
| 100 | +| `[bridge_indexer]` | Bridge API URL, MongoDB, fee discount, token whitelist | |
| 101 | +| `[near]` | NEAR RPC, bridge contract IDs, signer credentials | |
| 102 | +| `[eth]`, `[base]`, `[arb]`, `[bnb]`, `[pol]` | Per-chain RPC URLs, bridge addresses, finalization settings | |
| 103 | +| `[solana]` | Solana RPC, program IDs, discriminators | |
| 104 | +| `[btc]`, `[zcash]` | UTXO chain RPC and light client settings | |
| 105 | +| `[eth.fee_bumping]` | EVM transaction fee bumping thresholds | |
| 106 | + |
| 107 | +## Architecture |
| 108 | + |
| 109 | +``` |
| 110 | +Indexers (NEAR / EVM / Solana / MongoDB) |
| 111 | + └─► NATS OMNI_EVENTS stream |
| 112 | + └─► Bridge Indexer consumer |
| 113 | + └─► NATS RELAYER stream |
| 114 | + └─► Worker pool (process_events) |
| 115 | + └─► OmniConnector SDK ─► destination chain |
| 116 | +``` |
| 117 | + |
| 118 | +1. **Indexers** watch source chains for bridge events |
| 119 | +2. Events flow through NATS JetStream with at-least-once delivery |
| 120 | +3. **Workers** validate fees, build proofs, and finalize transfers via the OmniConnector SDK |
| 121 | +4. **Fee bumping** monitors pending EVM transactions and resubmits with higher gas when stuck |
| 122 | + |
| 123 | +## Building from Source |
| 124 | + |
| 125 | +If you prefer to run without Docker: |
| 126 | + |
| 127 | +```bash |
| 128 | +# Prerequisites: Rust 1.86+, running Redis, running NATS with JetStream |
| 129 | + |
| 130 | +# Create JetStream streams (one-time setup) |
| 131 | +nats stream add OMNI_EVENTS --subjects "omni-events.>" --retention limits --storage file --discard old |
| 132 | +nats stream add RELAYER --subjects "relayer.tasks.>" --retention limits --storage file --discard old |
| 133 | + |
| 134 | +# Build and run |
| 135 | +cp .example-env .env |
| 136 | +cp example-devnet-config.toml config.toml |
| 137 | +# Edit .env and config.toml |
| 138 | + |
| 139 | +cargo run -- --config config.toml |
| 140 | +``` |
0 commit comments