Strategies

Templates with a field schema, market-based suggestions, preview against the market, one-transaction deploy and rebalance plans for MeshPoolV3 strategies.

A strategy is a template expanded into MeshPoolV3 pools. The server never signs: your client funds every pool in one transaction, then registers it.

GET  /templates       → render the form from the field schema
GET  /suggest         → market mid + suggested params
POST /preview         → exact pools, addresses, deposits, prices vs mid
     … wallet: one tx, one output per pool (raw lockingBytecode, deposit) …
POST /                → register { template, ownerPkh, params, txid }
GET  /?owner=, /:id   → positions
POST /:id/rebalance-plan → close N, open M, one tx; register with `replaces`

Units:

Write routes are rate-limited.

GET /api/v1/strategies/templates

Every template with a field schema a client can render without knowing the template, plus shared limits.

Field types:

GET /api/v1/strategies/suggest

Market context and suggested params around the mid (deposits are left to you).

Parameter In Type Required Description
template query string yes Template id.
token query string no Token category (most templates).
tokens query string no multi-pair: 2–3 comma-separated categories.
tokenA query string no stable-pair: token A (with tokenB).

The mid is the deepest Cauldron pool's price. Without one, it is the middle of the best Mesh bid and ask, or the one side that exists.

Mid check. Each market context carries midCheck: the median of the mid samples of the last windowSec (30 minutes), how far the current mid is from it (divergenceBps) and ok. When a mid has jumped by more than maxDivergenceBps (5%), for example after one large trade on a thin Cauldron pool, /suggest returns params: null with a reason, so no position is centred on that price. You can still enter prices yourself.

Suggestions:

Template Suggested
fixed / spread bid at −0.5%, ask at +0.5%
recycling-pair buy at −1%, sell at +1%
grid −5% to +5%, 4 rungs, centerSatsPerToken = the mid (rungs above it start on the token side)
range −5% to +5%, 1% bins, spot, centerSatsPerToken = the mid
take-profit / accumulate +2% to +15% / −2% to −15%, 4 steps
multi-pair every token at −0.5%
stable-pair the peg (ratio of the two mids), 0.20% spread, 0.10% fee

POST /api/v1/strategies/preview

Template + params → the pools to fund, their addresses and deposits, and every price against the market mid. No chain access.

Per slot, side is buys (BCH reserve paying for a token), sells (token reserve asking BCH) or swaps (token↔token, with vsMidBps comparing the value given to the value received). Fund each pool with an output to its lockingBytecode (raw bytecode, not a wallet "send to address") carrying deposit. Token pools take 1000 sats plus the tokens.

The preview also returns:

Shapes. grid, range, take-profit and accumulate take shape (spot default, curve, bidask) and strength (gentle, standard, aggressive); see Range.

POST /api/v1/strategies

Register a deploy transaction: every pool's outpoint is found on-chain first, then all are registered (all or nothing). Pass replaces to link a rebalance.

GET /api/v1/strategies/:id

A position: totals over every member pool (mirrors included) and the pools themselves. GET /api/v1/strategies?owner=<pkh|cashaddr> lists summaries.

feeApr7dPct is an estimate: the last 7 days of fee income, annualised over the current value. It is null until the strategy has 24 hours of history. Owner listings (?owner=) also carry idle (kinds, reasons, valueSats) when part of the strategy is idle.

Metrics. Each strategy also carries metrics (estimates, for display):

Field Meaning
holdValueSats What your own deposits would be worth today if simply held. Deposits one of the strategy's pools made into another (recycling) are not counted
vsHoldSats, vsHoldPct Value now plus everything paid out, minus holdValueSats
arbitrage Fills and the share of volume that came from arbitrage (the Mesh Balancer, or transactions built outside the server)
range, timeInRange The prices the strategy quotes, and the share of market samples since it was deployed that fell inside them
stress.rows[] Value at 0.5×–2× the mid against holding what it holds now: each pool the move crosses converts at its own price

Proceeds. fixed, spread, take-profit and accumulate take proceeds: "wallet" | "recycle" (default wallet).

POST /api/v1/strategies/:id/rebalance-plan

Close the strategy's pools and open a new set in one transaction: the plan lists what to dock, what to fund and any shortfall.

Sign every close UTXO with dock(ownerPk, ownerSig), fund every open pool, and add wallet inputs for the fee and any shortfall. Then register with replaces.