Skip to content

feat(replay): pool-state tape covers every exact-curve venue#415

Merged
eeiaao merged 3 commits into
mainfrom
feat/pool-state-tape-all-venues
Jun 11, 2026
Merged

feat(replay): pool-state tape covers every exact-curve venue#415
eeiaao merged 3 commits into
mainfrom
feat/pool-state-tape-all-venues

Conversation

@eeiaao

@eeiaao eeiaao commented Jun 10, 2026

Copy link
Copy Markdown
Member

Extends the pool-state tape (#399, #400, #404) to the remaining exact-curve venues, so a StableSwap, Weighted, Cryptoswap, or Meteora DLMM pool can be recorded and replayed as a delta log too — until now those curves were backtest-only and their pool history had no tape format.

What changed:

  • PoolVenue grows StableSwap / Weighted / Cryptoswap / MeteoraDlmm, plus isBalancesShaped. Each venue gets a shaped Descriptor (its static parameters) and Checkpoint: the full balance vector for the n-token pools, the bin book + volatility-accumulator state for DLMM. Cryptoswap's price scale rides in its Checkpoint, not the Descriptor — the chain repegs it, so it is state, and a repeg between checkpoints re-anchors instead of corrupting the replay.
  • A new n-token SwapDelta (swapN) names its (i, j) pair explicitly, distinguished from the directional record by payload size, so old tapes replay unchanged. On the pair the connector presents it prints a trade; off it (a 3pool USDC→USDT swap while the connector presents DAI/USDC) the shared state still moves and the book republishes, with no trade on the symbol.
  • MeteoraDlmmCurve::applySwap now actually moves the bin reserves it quotes from: the walk records per-bin fills and the apply adds each bin's net input and removes its output. This matches the program's Bin::swap exactly — amount_into_bin = amount_in_with_fees - fee, the whole fee (LP share included) stays out of amount_x/amount_y as claimable — verified against the lb_clmm source, so a replayed bin book matches an on-chain readback to the unit. The curve also exposes the checkpoint surface a recorder needs (activeId, bins, volatility, timestamp).
  • The drift check compares every balances() entry, not just the first two, so an n-token pool's unobserved mutation on any coin is caught.

Validation:

  • Round-trip tests per venue against an independently-applied curve: 3pool StableSwap (including an off-pair swap moving state without a trade print), an 80/20 Weighted pool through the directional record, tricrypto Cryptoswap re-anchoring its price scale, and a DLMM swap walking bins down with the closing checkpoint captured off the expected post-state. Plus a balances-shaped drift test.
  • The DLMM curve test now asserts the post-apply reserves (output leaves exactly as quoted, input lands net of fee, the active bin moved).
  • Existing CP / CLMM round-trip, drift, and unknown-record tests unchanged and green; full suite 126/126.

MCP impact

None. No public binding surface change; docs FTS index regenerated.

W23-T001

eeiaao added 3 commits June 10, 2026 19:00
The tape's replay was limited to constant-product and CLMM venues; the
StableSwap, Weighted, Cryptoswap, and Meteora DLMM curves existed for
backtests but their pool history could not be recorded or replayed.

- PoolVenue grows StableSwap / Weighted / Cryptoswap / MeteoraDlmm, each
  with a venue-shaped Descriptor and Checkpoint: the full balance vector
  for the n-token pools (Cryptoswap also re-anchors its price scale,
  which the chain repegs), and the bin book + volatility state for DLMM.
- An n-token SwapDelta names its (i, j) pair explicitly; a swap off the
  connector's presented pair still moves the shared pool state and
  republishes the book, without printing a trade on the symbol.
- MeteoraDlmmCurve::applySwap now moves the bin reserves it quotes from
  (each filled bin gains its net input and loses its output; the fee
  part is not compounded, so an on-chain checkpoint re-anchors it as
  drift), and the curve exposes the checkpoint surface (activeId, bins,
  volatility, timestamp) a recorder needs.
- The drift check compares every balance entry, not just the first two.

Round-trip, off-pair, and drift tests for each new venue; the tape docs
describe the new checkpoint shapes.
Verified against the lb_clmm program source (Bin::swap): the bin gains
amount_into_bin = amount_in_with_fees - fee -- the entire fee, LP share
included, is tracked outside amount_x/amount_y as claimable. The replayed
bin reserves therefore match an on-chain readback exactly; the earlier
comments framed this as an unmodelled compounding, which was wrong.
@eeiaao eeiaao merged commit 90824b0 into main Jun 11, 2026
46 checks passed
@eeiaao eeiaao deleted the feat/pool-state-tape-all-venues branch June 11, 2026 02:43
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