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:
- prices are decimal strings in sats per token base unit;
- deposits are base-unit integer strings;
- BCH is
0xin pool data.
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:
token,price,rate,amount,int,bps,enum(withoptions), andtokenList(multi-pair).assetnames the token field a price or amount refers to (bchfor sats). It can also be{ "field": "side", "map": { "bid": "bch", "ask": "token" } }when a choice picks the unit.
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:
crossesMarketon each pool, andwarningsin words. A pool listed there gives a trader more than the market after its fee (a bid above the mid, an ask below it), so arbitrage would take it as soon as it is funded. Don't deploy it unless the LP means to. The rebalance and recycle plans carry the samewarnings.notes, e.g. a bin a shaped split left out because its share was below the pool minimum.deployBytes: a rough size of the deploy transaction.
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).
spreadwithrecycleputs both pools in mirror mode, so each side refills the other.fixedwithrecycleneedsrecycleSatsPerToken: the trade-back price, above a bid or below an ask.take-profitandaccumulatewithrecycle: a filled step trades back one step away (buys back lower, or sells back higher).
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.