optimizer

module
v0.5.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2026 License: MIT

README

Catscope Optimizer

Run a web assembly bot that will run in the Catscope runtime over Solpipe. A local Solpipe bidder daemon sets up a gRPC tunnel to a validator. The Optimizer code base talks with the local Solpipe bidder daemon to access the target Validator (Pipeline=2Gi87bD2MNKFREReqkJgcLodkBuQEcYGKaaWz45i2Nbo). ./brain is the generic, mode-agnostic bot-orchestration layer (see its own package doc comment); each trading/monitoring mode is one of its sibling packages -- currently ./brain/marketwatchv1, ./brain/testperplatencyv1, and ./brain/xstockshealthv1. The solpipe bidder proxy described in the Catscope quick start tutorial must be running before the optimizer will work.

Build the CLI:

make
  • the resuling binary will be in ./bin/optimizer

Every command below takes <parent-key>, a file path to a Solana-CLI-format keypair JSON file (the fee payer/treasury parent -- not the bidder proxy's own fee payer). They all also expect a local Solpipe bidder daemon already running at its default sockets (~/.solpipe.bidder.manage.sock, ~/.solpipe.bidder.proxy.sock) -- override via the MANAGER_SOCKET/PROXY_SOCKET/STATE_URL/TXPROC_URL environment variables if yours runs elsewhere. Set PROGRAM_SOLPIPE to the real on-chain Solpipe program id if the compiled-in default doesn't match the deployment you're pointed at. Any of these can go in a .env file in the working directory instead of being exported by hand.

Populating prefetch.db

Every brain mode reads its market/lending data from a local SQLite database at ~/.optimizer/prefetch.db, not live from chain -- populate (or refresh) it first:

./bin/optimizer download-arb <parent-key>

This walks every tracked DEX (Orca, Raydium AMM/CLMM/CPMM, Pumpswap, Pumpfun, Phoenix) and lending protocol (Solend, Kamino, Marginfi, Drift, Jet) via the bidder daemon's own state connection and writes the result into prefetch.db. Use --exact=orca,raydium_amm,... to scope it to specific sources, or --force to re-fetch everything even if already populated.

As its last step this command also compiles a release wasm bot image from the data it just wrote, as a smoke test -- see "Reaching each brain" below for what that needs (REPO, a wasm32-wasip2 Rust toolchain). If that compile fails, the command reports an error, but prefetch.db itself has already been populated by that point regardless.

Reaching each brain

Each brain mode needs two things beyond a populated prefetch.db:

  • REPO (environment variable), pointing at a local checkout of catscope-rust-bot with a wasm32-wasip2-capable Rust toolchain (rustup target add wasm32-wasip2). Every mode compiles that repo into a release .wasm binary -- statically embedding the prefetch data above -- and uploads it to the validator pipeline before doing anything else. Clone the catscope-rust-bot repository from here.
  • Optionally --working-dir (defaults to ~/.optimizer) and --state-url (defaults to the bidder daemon's own state connection).
# brain/marketwatchv1 -- read-only, never trades; live terminal dashboard
# of SOL/JUP/JTO/BONK/WIF/RAY volatility/correlation.
REPO=/path/to/catscope-rust-bot ./optimizer market-watch <parent-key>

# brain/testperplatencyv1 -- real-transaction, 100x-cycled deposit/withdraw
# latency test. Scope to one protocol with
# --protocol=solend|kamino|marginfi|native|native_lite, or leave unset
# for the original full unscoped sequence.
REPO=/path/to/catscope-rust-bot ./optimizer testperp-latency <parent-key>

# brain/xstockshealthv1 -- passive watcher: logs a health-factor board for
# Kamino xStocks obligations/reserves, sends no transactions. Serves a
# local page at --dashboard-addr (default 127.0.0.1:8091).
REPO=/path/to/catscope-rust-bot ./optimizer xstocks-health <parent-key>

Run ./bin/optimizer <command> --help for every flag a given mode accepts, and see ./brain's own package doc comment for how a new mode plugs into this same upload/handshake flow.

Directories

Path Synopsis
Command harness is a minimal tool-calling agent, built the same way as go-wiki/examples/eino-ollama-agent/main.go (github.com/cloudwego/eino's prebuilt ReAct agent: call the model -> if it asked for a tool, run the tool and feed the result back -> repeat until the model answers without a tool call), but with walletTools() (see tools.go) in place of that example's demoTools().
Command harness is a minimal tool-calling agent, built the same way as go-wiki/examples/eino-ollama-agent/main.go (github.com/cloudwego/eino's prebuilt ReAct agent: call the model -> if it asked for a tool, run the tool and feed the result back -> repeat until the model answers without a tool call), but with walletTools() (see tools.go) in place of that example's demoTools().
Package brain is a generic, mode-agnostic bot-orchestration layer: it allocates a slot on a Catscope/Solpipe validator pipeline, then uploads whatever WASM bot images are requested of it over time (via Request), handing back a Bot object per upload -- the running instance's handshake, an on-disk log file of its stderr output, and plain Go channels for its stdin/stdout messaging.
Package brain is a generic, mode-agnostic bot-orchestration layer: it allocates a slot on a Catscope/Solpipe validator pipeline, then uploads whatever WASM bot images are requested of it over time (via Request), handing back a Bot object per upload -- the running instance's handshake, an on-disk log file of its stderr output, and plain Go channels for its stdin/stdout messaging.
marketwatchv1
Package marketwatchv1 is the Go-side orchestrator for the marketwatchv1 bot mode -- forked from optimizer/brain/arbv1, stripped of every trading-specific piece (no wallet, no latency-file, no bundler tip wiring).
Package marketwatchv1 is the Go-side orchestrator for the marketwatchv1 bot mode -- forked from optimizer/brain/arbv1, stripped of every trading-specific piece (no wallet, no latency-file, no bundler tip wiring).
testperplatencyv1
Package testperplatencyv1 is the Go-side orchestrator for the testperplatencyv1 bot mode -- a real-transaction latency test, not a real trading strategy.
Package testperplatencyv1 is the Go-side orchestrator for the testperplatencyv1 bot mode -- a real-transaction latency test, not a real trading strategy.
xstockshealthv1
Package xstockshealthv1 is the Go-side orchestrator for the xstockshealthv1 bot mode.
Package xstockshealthv1 is the Go-side orchestrator for the xstockshealthv1 bot mode.
Package bundler defines account bundling schemes
Package bundler defines account bundling schemes
astralane
Package astralane wraps bundler functionality
Package astralane wraps bundler functionality
jito
Package jito wraps jito
Package jito wraps jito
cmd
localdevserver command
Command localdevserver spins up a real machinev1.Machine + builderv1.FileSystemWrapper gRPC server backed entirely by local directories and local subprocesses (harness/localdev), instead of real Firecracker guests (gitlab.noncepad.com/eflam/qemu-pool).
Command localdevserver spins up a real machinev1.Machine + builderv1.FileSystemWrapper gRPC server backed entirely by local directories and local subprocesses (harness/localdev), instead of real Firecracker guests (gitlab.noncepad.com/eflam/qemu-pool).
tmpverifymw command
examples
eino-ollama-agent command
Command eino-ollama-agent is a minimal example of building a tool-calling agent with github.com/cloudwego/eino.
Command eino-ollama-agent is a minimal example of building a tool-calling agent with github.com/cloudwego/eino.
telnet command
gen
Package grpcauth makes the caller's identity, carried in the "USER" gRPC metadata key, available to RPC handlers via context.Context.
Package grpcauth makes the caller's identity, carried in the "USER" gRPC metadata key, available to RPC handlers via context.Context.
Package harness implements interfaces in the ./api directory.
Package harness implements interfaces in the ./api directory.
localdev
Package localdev implements api.BotCoder/api.BotCompiler/ api.FilesystemWrapper directly against the local filesystem and local subprocesses, instead of dialing a real machinev1/builderv1 gRPC server backed by a Firecracker guest over SFTP (see harness's own compiler.go/fs.go) - for fast local iteration against this package's own interfaces without needing that infrastructure running at all.
Package localdev implements api.BotCoder/api.BotCompiler/ api.FilesystemWrapper directly against the local filesystem and local subprocesses, instead of dialing a real machinev1/builderv1 gRPC server backed by a Firecracker guest over SFTP (see harness's own compiler.go/fs.go) - for fast local iteration against this package's own interfaces without needing that infrastructure running at all.
Package portfolio persists bot balance snapshots (each tagged with the token's USD price at capture time) to a local SQLite database, and computes PnL from them.
Package portfolio persists bot balance snapshots (each tagged with the token's USD price at capture time) to a local SQLite database, and computes PnL from them.
Package prefetch builds wasm bots preloaded with necessary information
Package prefetch builds wasm bots preloaded with necessary information
alt
Package alt persists Address Lookup Table contents to prefetch.db -- see cmd/alt.go, the only writer.
Package alt persists Address Lookup Table contents to prefetch.db -- see cmd/alt.go, the only writer.
drift
Package drift preloads Drift v2 SpotMarket accounts (global market data only -- User, the per-wallet position account, is not fetched here since there is no bounded set to bulk-load, and PerpMarket is skipped since it has no mint/vault of its own -- perp markets settle in the program's quote asset).
Package drift preloads Drift v2 SpotMarket accounts (global market data only -- User, the per-wallet position account, is not fetched here since there is no bounded set to bulk-load, and PerpMarket is skipped since it has no mint/vault of its own -- perp markets settle in the program's quote asset).
jet
Package jet preloads Jet Protocol V1 lending pool reserve accounts (global market data only -- Obligation, the per-wallet position account, is not fetched here since there is no bounded set to bulk-load).
Package jet preloads Jet Protocol V1 lending pool reserve accounts (global market data only -- Obligation, the per-wallet position account, is not fetched here since there is no bounded set to bulk-load).
kamino
Package kamino preloads Kamino Lending reserve accounts.
Package kamino preloads Kamino Lending reserve accounts.
liquidity
Package liquidity generates router.json for the catscope-rust-bot build.
Package liquidity generates router.json for the catscope-rust-bot build.
lst-yield
Package lstyield estimates real Solana liquid-staking-token (LST) staking yield from a periodic SOL-per-LST exchange-rate timeseries, so perpfundingv1's leveraged-yield-farming plan (see catscope-rust-bot/src/brain/leveraged_yield_farming_plan.md, "Phase 0") and leveragedloopv1's Time-Expanded DAG (see catscope-rust-bot/src/trader/TIME.md) have a real profitability signal for LST-collateral loops.
Package lstyield estimates real Solana liquid-staking-token (LST) staking yield from a periodic SOL-per-LST exchange-rate timeseries, so perpfundingv1's leveraged-yield-farming plan (see catscope-rust-bot/src/brain/leveraged_yield_farming_plan.md, "Phase 0") and leveragedloopv1's Time-Expanded DAG (see catscope-rust-bot/src/trader/TIME.md) have a real profitability signal for LST-collateral loops.
marginfi
Package marginfi preloads marginfi-v2 Bank accounts (global market data only -- MarginfiAccount, the per-wallet position account, is not fetched here since there is no bounded set to bulk-load).
Package marginfi preloads marginfi-v2 Bank accounts (global market data only -- MarginfiAccount, the per-wallet position account, is not fetched here since there is no bounded set to bulk-load).
mintinfo
Package mintinfo provides a small shared cache of SPL Mint decimals, populated opportunistically by every prefetcher that discovers a mint (Orca, Raydium AMM/CPMM/CLMM) so a mint referenced by many pools (USDC, wSOL) is only ever fetched once per run, not once per pool.
Package mintinfo provides a small shared cache of SPL Mint decimals, populated opportunistically by every prefetcher that discovers a mint (Orca, Raydium AMM/CPMM/CLMM) so a mint referenced by many pools (USDC, wSOL) is only ever fetched once per run, not once per pool.
multimodel
Package multimodel persists multimodelv1's cross-restart residual/ z-score warm-up snapshot into prefetch.db, one row per mint -- see schema.sql's doc comment for why one row/message per mint, not one big batch.
Package multimodel persists multimodelv1's cross-restart residual/ z-score warm-up snapshot into prefetch.db, one row per mint -- see schema.sql's doc comment for why one row/message per mint, not one big batch.
obligation
Package obligation records this bot's own Solend/Kamino lending obligation state (deposits/borrows, across multimodelv1's pair/ directional/hawkes trade types) into prefetch.db, the same skip-if-unchanged shape optimizer/prefetch/pnl uses for wallet token balances -- see this package's schema.sql for the real motivation (there was previously no way to see this state without manually deriving each obligation's address and parsing its raw account bytes).
Package obligation records this bot's own Solend/Kamino lending obligation state (deposits/borrows, across multimodelv1's pair/ directional/hawkes trade types) into prefetch.db, the same skip-if-unchanged shape optimizer/prefetch/pnl uses for wallet token balances -- see this package's schema.sql for the real motivation (there was previously no way to see this state without manually deriving each obligation's address and parsing its raw account bytes).
orca
Package orca preloads Orca Whirlpool trading pools.
Package orca preloads Orca Whirlpool trading pools.
phoenix
Package phoenix preloads Phoenix perpetuals market identity (symbol, asset_id, market_account) into prefetch.db.
Package phoenix preloads Phoenix perpetuals market identity (symbol, asset_id, market_account) into prefetch.db.
pnl
Package pnl records a trading wallet's token position history into prefetch.db and computes mark-to-market PnL from it: the market value of a position at its earliest known snapshot vs.
Package pnl records a trading wallet's token position history into prefetch.db and computes mark-to-market PnL from it: the market value of a position at its earliest known snapshot vs.
price-feed
Package pricefeed polls the Jupiter Price API v3 for a configurable list of token mints and publishes price updates on a channel.
Package pricefeed polls the Jupiter Price API v3 for a configurable list of token mints and publishes price updates on a channel.
pumpfun
Package pumpfun preloads Pump.fun bonding-curve state.
Package pumpfun preloads Pump.fun bonding-curve state.
pumpswap
Package pumpswap preloads PumpSwap AMM pool state.
Package pumpswap preloads PumpSwap AMM pool state.
pyth
Package pyth decodes Pyth Push Oracle price accounts and derives their well-known PDAs -- a Go port of catscope-rust-bot's own src/trader/dex/pyth.rs (parse_push_oracle and the SOL/USD feed account derivation); offsets/behavior are verified there against a real, live mainnet account, not re-derived here.
Package pyth decodes Pyth Push Oracle price accounts and derives their well-known PDAs -- a Go port of catscope-rust-bot's own src/trader/dex/pyth.rs (parse_push_oracle and the SOL/USD feed account derivation); offsets/behavior are verified there against a real, live mainnet account, not re-derived here.
raydium
Package raydium preloads Raydium AMM v4 trading pools.
Package raydium preloads Raydium AMM v4 trading pools.
raydium/amm
Package amm tracks amm
Package amm tracks amm
raydium/clmm
Package clmm tracks clmm
Package clmm tracks clmm
raydium/cpmm
Package cpmm tracks cpmm
Package cpmm tracks cpmm
sanctum
Package sanctum preloads Sanctum S Controller LST pool state.
Package sanctum preloads Sanctum S Controller LST pool state.
solend
Package solend preloads Solend/Save token-lending reserve accounts (global market data only -- Obligation, the per-wallet position account, is not fetched here since there is no bounded set to bulk-load).
Package solend preloads Solend/Save token-lending reserve accounts (global market data only -- Obligation, the per-wallet position account, is not fetched here since there is no bounded set to bulk-load).
trading
Package trading holds common structs
Package trading holds common structs
Package shell sets up a telnet endpoint
Package shell sets up a telnet endpoint
Package store persists prefetched on-chain data to a local SQLite database.
Package store persists prefetched on-chain data to a local SQLite database.
Package util contains generic functions.
Package util contains generic functions.
Package wiki
Package wiki
chat
Package chatclient is a real gRPC client for chat.v1.ChatService (see chatserver's own doc comment for the server side, and proto/chat/v1/chat.proto for the RPC surface itself).
Package chatclient is a real gRPC client for chat.v1.ChatService (see chatserver's own doc comment for the server side, and proto/chat/v1/chat.proto for the RPC surface itself).
chattui
Package chattui is a terminal UI for chat.v1.ChatService, built on chatclient (the same gRPC client cmd/wiki-client's HTTP chat routes use - see wiki/remote/chat.go) - so this is a second, terminal-based front end for the same chat feature, not a reimplementation of it.
Package chattui is a terminal UI for chat.v1.ChatService, built on chatclient (the same gRPC client cmd/wiki-client's HTTP chat routes use - see wiki/remote/chat.go) - so this is a second, terminal-based front end for the same chat feature, not a reimplementation of it.
ledger
Package ledger wraps a wiki client for doing accounting.
Package ledger wraps a wiki client for doing accounting.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL