72 lines
3.6 KiB
Markdown
72 lines
3.6 KiB
Markdown
# Scripts
|
||
|
||
## size-inventory.cjs
|
||
|
||
Regenerates **I_T^*** (inventory target) and suggested **D_0** per chain per cW token from `config/simulation-params.json`. Output includes assumptions (σ, T_refill/T_epoch, β, γ). Keeps configs honest and PRs reviewable.
|
||
|
||
**Run from repo root (cross-chain-pmm-lps):**
|
||
|
||
```bash
|
||
node scripts/size-inventory.cjs
|
||
```
|
||
|
||
**Options:**
|
||
|
||
- `--sigma 1.8` — override USD stress multiplier (default 1.5)
|
||
- `--refill-ratio 0.33` — T_refill / T_epoch (default 0.33)
|
||
- `--depth-mult 0.75` — D_0 = depth_mult * I_T^* (default 0.75)
|
||
- `--v-epoch '{"1":100000,"56":80000,"137":60000}'` — per-chain V_epoch (JSON object)
|
||
|
||
**Environment:** `V_EPOCH_<chainId>` overrides V_epoch for that chain (e.g. `V_EPOCH_1=100000`).
|
||
|
||
**Output:** JSON with `assumptions` and per-chain per-token `I_T_star`, `D_0`, `V_epoch`, `sigma`, `beta`, `gamma`, and EUR stress flag where applicable.
|
||
|
||
---
|
||
|
||
## validate-deployment-status.cjs
|
||
|
||
Validates `config/deployment-status.json` for minimum viable deployed graph. Use in CI so deployment-realistic sim cannot run with half-filled state.
|
||
|
||
**Rules:**
|
||
|
||
- If `bridgeAvailable === true` on a chain, `cwTokens` must include at least **cWUSDT** and **cWUSDC** (phase 1).
|
||
- For each `pmmPool`: `role` ∈ {defense, public_routing}; `feeBps` and `k` present; `base`/`quote` (or `tokenIn`/`tokenOut`) exist in `cwTokens` or `anchorAddresses`.
|
||
|
||
**Run:**
|
||
|
||
```bash
|
||
node scripts/validate-deployment-status.cjs
|
||
```
|
||
|
||
**Exit code:** 0 if valid, 1 if invalid (errors to stderr).
|
||
|
||
---
|
||
|
||
## run-scenario.cjs
|
||
|
||
Builds the **real** routing graph from configs, runs epochs with PMM state updates, path enumeration + waterfilling, **arb step** (implied-price deviation, capped corrective trades, profit gate), **bot step** (inject/withdraw at 0.5×/1.5× I_T^* with intervention cost β/γ/ρ), and optional **bridge shock** trades. Emits a **real scorecard** (PR#2). Runs are **deterministic** when `scenario.seed` is set or derived from scenario name.
|
||
|
||
**Configs used:** `simulation-params.json`, `token-map.json`, `routing-controls.json`; `deployment-status.json` only when `graphMode = deployed`. Pool topology from `pool-matrix.json` and scenario `topology` / `fullQuoteChains`.
|
||
|
||
**Tuning constants (in script):**
|
||
|
||
| Constant | Value | Purpose |
|
||
|----------|--------|---------|
|
||
| `PROBE_SIZE` | 1000 | Units for path cost probe (k-shortest by cost) |
|
||
| `K_PATHS` | 5 | Max candidate paths per trade for waterfilling |
|
||
| `CHUNK_FRACTION` | 0.05 | 5% of trade per chunk; marginal-equalization step size |
|
||
| `AMM_DEPTH_UNITS` | 10e6 | Background AMM depth (notional; infinite-depth approx in code) |
|
||
| `AMM_FEE_BPS` | 5 | Fee for anchor↔anchor stable swaps |
|
||
|
||
**Run:**
|
||
|
||
```bash
|
||
node scripts/run-scenario.cjs hub_only_11
|
||
node scripts/run-scenario.cjs --scenario full_quote_1_56_137
|
||
node scripts/run-scenario.cjs bridge_shock_137_56
|
||
```
|
||
|
||
**Output:** JSON scorecard including: `capture_mean`, `churn_mean`, `drain_half_life_epochs`, `path_concentration_index`; `intervention_cost_total` / `intervention_cost_inject_total` / `intervention_cost_withdraw_total` / `intervention_cost_by_chain` / `intervention_cost_per_1M_volume`; `peak_deviation_bps` (post-arb), `peak_deviation_bps_pre_arb`, `peak_deviation_bps_post_arb`, `peak_deviation_bps_post_bot`; `arb_volume_total`, `arb_profit_total` (execution-based, not mid). See [docs/12-sim-scorecard.md](../docs/12-sim-scorecard.md) and [config/scorecard-schema.json](../config/scorecard-schema.json).
|
||
|
||
**Orderflow:** Trade sizes use `distribution: "uniform"` by default. Scenario schema supports `lognormal` / `pareto` for skewed (many small + occasional whale) flows; implement in `sampleTrade()` when needed.
|