Files
cross-chain-pmm-lps/spec/bot-pseudo-code.md
defiQUG 168dba25d9 chore(sim): refresh deployment status, pool matrix, schemas, and scenario scripts
- deployment-status and pool-matrix snapshots aligned with validate-deployment-status.cjs.
- Micro-trade / scorecard docs and run-scenario wiring.

Made-with: Cursor
2026-04-07 22:56:16 -07:00

39 lines
1.5 KiB
Markdown

# Bot Pseudo-Code (Watcher + Rebalance)
## Per-pool loop (v1)
```
for each pool (cW* / quote):
P_oracle = getOraclePrice(T)
P_pool = getPoolMidPrice(T)
δ = (P_pool - P_oracle) / P_oracle
inv = getInventoryImbalance(T)
if |δ| > circuitBreakBps:
setState(CIRCUIT_BREAK)
continue
if inCooldown(pool):
continue
if δ > normalBandBps:
sell T into pool (size within budget)
setCooldown(pool)
else if δ < -normalBandBps:
buy T from pool (size within budget)
setCooldown(pool)
if inv outside threshold:
schedule inventory re-center (add/remove single-sided T, or bridge)
```
## v2 additions
- **Route selection**: Among pools for same T (e.g. T/USDC, T/USDT, T/DAI), choose edge with lowest slippage + fee; execute there; optionally rebalance quote via DEX.
- **Bridge throttle**: If bridge backlog or risk flag, widen bands or skip trade.
- **Global budget**: Before any trade, check per-token trade budget for current window; skip if exhausted.
- **Min improvement**: Only trade if expected |δ| improvement net of fees ≥ minImprovementBps.
- **Gas-budgeted micro-support**: For selected USD wrappers (especially `cWUSDC`, `cWUSDT`), allow tiny matched-quote trades (`cWUSDC/USDC`, `cWUSDT/USDT` when available) under a separate gas budget so wrappers stay economically live without converting the PMM into the destination venue.
Thresholds and bands from [../config/peg-bands.json](../config/peg-bands.json). Mesh reflexivity from [../docs/07-mesh-reflexivity.md](../docs/07-mesh-reflexivity.md).