Skip to content

Release: L1-13 pool-capacity preflight + funding counterparty fix (staging → main) - #49

Merged
y4hyya merged 13 commits into
mainfrom
staging
Aug 27, 2026
Merged

Release: L1-13 pool-capacity preflight + funding counterparty fix (staging → main)#49
y4hyya merged 13 commits into
mainfrom
staging

Conversation

@y4hyya

@y4hyya y4hyya commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

What ships

  • L1-13 pool-capacity headroom preflight (a73e8bd): GET /v1/markets/stats gains per-asset capacity + vault-wide pool (chain-read, omitted on failure); OrderPanel clamps market orders past the headroom with a gate-specific banner; Long/Short stat; fixes the trade-page OI / 24h-volume tiles that rendered "—" since 07-04 (stats?.assets vs {stats}); sdk-ts/sdk-py parity; shared math with a 3,000-case parity test against the vault predicate.
  • Funding counterparty fix (31f3b4c, 2cfa0fa, 53103c1): funding receivers are paid by the vault, never from custody; keeper skips redundant state writes and treats #90 freeze as not-due; spec + scripts/funding_params.sh.
  • Audit config snapshots (08-24 post-deposit, 08-26, 08-27 post-upgrade) and the market test-snapshot refresh.

Already live

  • Gateway noether-api:v14 (2026-08-26), keepers noether-keeper-t3:v10, prod + staging market upgrade (snapshots in audit/config-snapshots/).
  • Web: staging + testnet rolling from this tip; prod web deploy follows this merge (scripts/deploy_web_azure.sh prod).

Verification

Root typecheck clean; shared 14/14, api 157/157, sdk-ts 63/63, sdk-py 42/42, web tsc + lint clean; CI green on staging and testnet.

y4hyya added 13 commits August 22, 2026 22:50
…cout verbose

scripts/volume-bot/ lives only in the local tree (.git/info/exclude), so the
osv-scanner step's stat of its package-lock.json fails in every CI checkout —
broke the first weekly cron (2026-08-24, exit 127) and would fail every PR run.

Scout's quiet mode pipes the detector build's stderr to /dev/null; --verbose
keeps the real error in the log next time the build breaks.
…rm-cache runs

cargo-scout-audit performs its whole environment setup (nightly-2025-08-07,
rust-src/llvm-tools/rustc-dev, dylint-link) in its build.rs, which only runs
when the crate is compiled. With rust-cache restoring the binary, cargo
install is a no-op, ~/.rustup starts empty, and rustup's bare auto-install
provides a nightly without rustc_private crates — every warm-cache run died
with E0463 for all rustc_* crates (root cause of the 2026-08-24 cron failure;
run #1 passed only because its cache was cold). Install the toolchain and
components explicitly so the job no longer depends on scout's build script
having executed.
…hape fix

Traders hit the vault's capacity gates blind (#82 OpenInterestCapExceeded,
#89 SkewCapExceeded) after clicking Open — 2026-08-24 one tester's $148.6k of
one-sided XLM shorts exhausted the 15%-of-AUM net-skew budget on prod and
every further XLM short failed with no signal in the UI.

- packages/shared/capacity.ts: vaultAccepts (gate-by-gate transliteration of
  vault reserve_for_position) + computeHeadroom per side with the binding
  gate; 3,000-case parity test asserts size <= headroom <=> vault accepts,
  incl. the cap-already-breached reducing-side bound (|net| + max(cap, |net|)).
- api: ContractReader.readAssetExposure (one batched ledger read of the 14
  AssetExposure keys), CapacityService (5s hot / 300s params cache,
  stale-while-error 30s, omitted on failure — never zeroed), folded into
  GET /v1/markets/stats as per-row `capacity` + top-level `pool`. No new
  route. withTimeout hoisted to services/timeout.ts.
- web: OrderPanel clamps market orders past the headroom with a
  gate-specific banner + "Use max"; "Pool capacity" row in the order summary;
  Long/Short split in MarketStatsBar; trust gate (gatewayServesThisMarket +
  <60s data). Fixes the trade page reading `stats?.assets` while the gateway
  has always sent `{stats, solvency}` — the OI / 24h-volume tiles rendered
  "—" on every environment since 2026-07-04.
- sdk-ts / sdk-py: AssetCapacity / PoolCapacity types mirrored + tests.
- packages/shared gains vitest wiring (test script, config, devDep).
… the vault, never from custody

The market paid funding receivers out of its own USDC pool while funding
payers paid the vault, so every funding receipt drained other traders'
collateral. With funding_clamp_bps=100 and weeks of one-sided skew this
emptied the prod market (custody 27k vs 241k tracked; 1.1M accrued).

Settlement now nets price PnL and funding per closed portion: net>0 is paid
by the vault through settle_pnl (shortfall booked, ADL flagged), net<0
leaves the position's own collateral for the vault. Applies to isolated,
partial and cross closes; liquidation paths were already conserved.

Adds admin reseed_funding(ids) (full-freeze only) to void pending funding
accrued under the bug before unfreezing, scripts/funding_params.sh to
lower funding_clamp_bps/max_funding_velocity_bps on all pairs, and
receiver-side conservation tests (isolated, partial, cross, reseed).
…ot-due

saveKeeperState ran every 5s discovery cycle on the Azure Files mount
(~5M billed SMB ops/month). Writes are now skipped when byte-identical and
rate-limited to one per 60s unless forced (shutdown, funding applied).
apply_funding under an L0-15 full-freeze (#90) is treated like not-due
instead of a failure streak, so a planned freeze does not page.
Every market test snapshot embeds the contract WASM hash + code; 31f3b4c
changed the market (funding receivers paid by the vault) without regenerating
them. Output of the test run on the same commit — no test logic changed.
@y4hyya
y4hyya merged commit b1e4ec3 into main Aug 27, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant