Docs · Guides
Run Mesa on a local network
Run the whole Mesa stack on your machine with one command, open a funded account, move the oracle price, and point scripts at it.
The local network is Mesa with every part running on your machine: a Solana validator with the Privacy Rings programs and the Mesa program, the shielded indexer and prover, a drand beacon, an oracle you set by hand, and the API, indexer and keeper. Batches run, positions renew and lapse, and liquidations land, the same as on mainnet. Use it to test a script before it touches real funds, or to make a position lapse on purpose.
What you need
- Linux, macOS, or Windows with WSL2. Run every command below in that shell.
- Node 22 and Docker.
- The
zolanaCLI, releasecli-v0.10.0, at~/mesa-dev/bin/zolana, or withZOLANA_CLI_BINset to its path. - Rust 1.98.1 and Solana platform tools v1.54, to build the program.
- A checkout of the Mesa repository, with
npm installrun inbackend/.
Build the program
Once, and again after the program changes:
bash backend/program/scripts/build.shIt compiles the circuits and their keys, the browser and Node WASM packages, and the program, to ~/mesa-dev/target/deploy/mesa_program.so.
Start it
From the repository root:
bash dev/localnet/up.shIt starts each part in order and waits for each to answer:
Postgres
A container named
mesa-postgreson 127.0.0.1:23720.drand beacon
A local quicknet beacon on 127.0.0.1:23712, so batches open without waiting on the public network.
Validator, indexer and prover
Surfpool on 127.0.0.1:23730 (WebSocket 23731), Photon on 23734 and the Rings prover on 23735, with the Privacy Rings programs and the Mesa program loaded.
Seed
Mints SOL, USDC and JITOSOL, writes
Config, creates the SOL/USDC market and vault, the three lending pools,SOL-PERPand its vault, and runs two batches so every market has history. It funds a test account. Running it again on a seeded chain sends nothing.Oracle
Writes the prices in
dev/localnet/prices.jsonon chain every 10 seconds.API, indexer and keeper
Syncs the circuits, builds the backend and starts all three. The API answers on 127.0.0.1:23714.
When it finishes, it prints each address and where the logs are. GET http://127.0.0.1:23714/health reads live.
Logs are in ~/mesa-dev/localnet/logs/ and dev/live/. Set MESA_LOCALNET_DIR before up.sh to keep the chain state somewhere else.
Open the funded account
The seed funds one test account with SOL, USDC and JITOSOL in its wallet, its Rings private balance and its Mesa balance. The local API hands out its key:
import { createClient } from '@mesa/contract'
import { openMesaScript } from '@mesa/sdk/node'
const apiUrl = 'http://127.0.0.1:23714'
const dev = await createClient(apiUrl).devWallet()
const mesa = await openMesaScript({ apiUrl, wallet: dev.secretKeyBase58 })
console.log(mesa.snapshot().balances)The script finds the validator, indexer and prover from the API's config. GET /v1/dev/wallet exists only on a local network. Every other call in this guide works the same against https://api.mesa.markets with your own key file.
Move the price
Edit dev/localnet/prices.json:
{
"SOL": 120.0,
"USDC": 1.0,
"JITOSOL": 140.0
}Within 10 seconds the oracle writes the new prices and the cross rates between the assets. A drop in SOL makes SOL-collateral borrows less healthy. Push it far enough and a position can no longer renew.
Make a position lapse
The local Config runs short timings, so you can watch a whole cycle in minutes. Read them from GET /v1/config: batchLengthSeconds, heartbeatSeconds.
- Open a borrow with SOL collateral from the funded account, near the collateral factor.
- Do not run a renew loop, and do not enrol the watcher.
- Lower
SOLinprices.json. - Wait for its deadline, the end of the heartbeat after the one it was opened in. The position lapses and shows in
lapsedPositions(). - Liquidate it from a second account. See Run a liquidator.
The keeper on the local network liquidates lapsed positions too, so your liquidator races it.
Stop it
bash dev/localnet/down.shIt stops only what up.sh started, read from the PID files up.sh wrote, and stops the Postgres container without removing its data.