Contracts: remove legacy Simulation; HybridSimulation default everywhere #190

Closed
opened 2026-05-26 07:59:16 +00:00 by PlasticDigits · 13 comments
PlasticDigits commented 2026-05-26 07:59:16 +00:00 (Migrated from gitlab.com)

Problem statement

Pair/router legacy Simulation / ReverseSimulation remain pool-only while Pattern C execution uses the on-chain FIFO book. Integrators and tooling that call legacy queries can mis-quote hybrid routes (invariant L8 in docs/contracts-security-audit.md).

Evidence / context

Proposed solution

  1. Deprecate and remove legacy Simulation / ReverseSimulation (or make them thin aliases that require explicit zero-book hybrid params with documented sunset).
  2. Default all quoting — pair, router, indexer LCD wrappers, dApp preflight — to HybridSimulation / HybridReverseSimulation (zero book_input = pool-only behavior).
  3. Update dex-common, integrator docs, and breaking-change notes.

Acceptance criteria

  • No production code path relies on pool-only Simulation for user-facing quotes.
  • Router SimulateSwapOperations uses hybrid queries whenever hybrid is set; default path documented for pool-only (zero book leg).
  • Contract tests updated; migration note for external integrators.
  • Indexer + frontend preflight migrated; CI green.

Priority

P1 (correctness / launch blocker for hybrid honesty)

## Problem statement Pair/router **legacy `Simulation` / `ReverseSimulation`** remain **pool-only** while Pattern C execution uses the on-chain FIFO book. Integrators and tooling that call legacy queries can **mis-quote** hybrid routes (invariant **L8** in [`docs/contracts-security-audit.md`](docs/contracts-security-audit.md)). ## Evidence / context - [`smartcontracts/contracts/pair/src/lib.rs`](smartcontracts/contracts/pair/src/lib.rs) — pool-only legacy queries documented. - [ADR 0001](docs/adr/0001-hybrid-quoting-and-routing.md) added `HybridSimulation` / `HybridReverseSimulation`; adoption is partial. - Indexer/frontend still reference pool `simulation` in places ([`swapRoutePreflight.ts`](frontend-dapp/src/services/terraclassic/swapRoutePreflight.ts)). ## Proposed solution 1. **Deprecate and remove** legacy `Simulation` / `ReverseSimulation` (or make them thin aliases that **require** explicit zero-book hybrid params with documented sunset). 2. **Default all quoting** — pair, router, indexer LCD wrappers, dApp preflight — to **`HybridSimulation`** / **`HybridReverseSimulation`** (zero `book_input` = pool-only behavior). 3. Update `dex-common`, integrator docs, and breaking-change notes. ## Acceptance criteria - [ ] No production code path relies on pool-only `Simulation` for user-facing quotes. - [ ] Router `SimulateSwapOperations` uses hybrid queries whenever `hybrid` is set; default path documented for pool-only (zero book leg). - [ ] Contract tests updated; migration note for external integrators. - [ ] Indexer + frontend preflight migrated; CI green. ## Priority **P1** (correctness / launch blocker for hybrid honesty)
PlasticDigits commented 2026-05-26 09:29:09 +00:00 (Migrated from gitlab.com)

Completely deprecate and remove legacy paths -as we are not yet deployed backwards compatibility not required.

Completely deprecate and remove legacy paths -as we are not yet deployed backwards compatibility not required.
PlasticDigits commented 2026-05-26 09:36:28 +00:00 (Migrated from gitlab.com)

mentioned in commit 7d57ccf535

mentioned in commit 7d57ccf5355918f8910a70cb68b37d4bba84ebf6
PlasticDigits commented 2026-05-26 09:36:28 +00:00 (Migrated from gitlab.com)

mentioned in commit 4b5365e0b9

mentioned in commit 4b5365e0b9226fba4d7702b668db1c9848125f15
PlasticDigits commented 2026-05-26 09:36:45 +00:00 (Migrated from gitlab.com)

Implemented (#190) — merged to main (7d57ccf)

Removed legacy pair Simulation / ReverseSimulation queries and migrated all quoting to HybridSimulation / HybridReverseSimulation only (per issue note: no backwards-compat aliases).

What changed

  • Contracts: Dropped QueryMsg::Simulation / ReverseSimulation; added pool_only_hybrid_params() and pool_only_hybrid_template() in dex-common. Router simulate_swap_operations always uses hybrid queries (pool-only when terra_swap.hybrid is null).
  • Indexer: hybrid_route_opt no longer calls legacy simulation LCD; degraded path uses hybrid_simulation with book_input: 0.
  • Frontend: simulateSwap / reverseSimulateSwap / swapRoutePreflight use hybrid_simulation via poolOnlyHybrid.ts.
  • Docs / agents: Updated invariant L8, ADR 0001 (merged with #189 route/solve/best text), integrator + limit-order docs; new skills/AGENTS_HYBRID_QUOTING.md.

Verification checklist

  • LCD hybrid_simulation with book_input: "0" matches prior pool-only quotes on a funded pair
  • LCD hybrid_reverse_simulation with pool_input: "1", book_input: "0" returns sensible offer_amount
  • Router simulate_swap_operations with hybrid: null hops matches direct pair hybrid pool-only quotes
  • Swap page / Trade panel quotes still load (simulateSwap → hybrid)
  • Indexer GET route/solve?hybrid_optimize=true still returns estimated_amount_out (no simulation LCD)
  • cargo test -p cl8y-dex-tests limit_order_tests green on your machine

@brouie — please run the checklist on your environment and confirm before we close this issue.

## Implemented (#190) — merged to `main` (`7d57ccf`) Removed legacy pair `Simulation` / `ReverseSimulation` queries and migrated all quoting to **`HybridSimulation` / `HybridReverseSimulation`** only (per issue note: no backwards-compat aliases). ### What changed - **Contracts:** Dropped `QueryMsg::Simulation` / `ReverseSimulation`; added `pool_only_hybrid_params()` and `pool_only_hybrid_template()` in `dex-common`. Router `simulate_swap_operations` always uses hybrid queries (pool-only when `terra_swap.hybrid` is null). - **Indexer:** `hybrid_route_opt` no longer calls legacy `simulation` LCD; degraded path uses `hybrid_simulation` with `book_input: 0`. - **Frontend:** `simulateSwap` / `reverseSimulateSwap` / `swapRoutePreflight` use `hybrid_simulation` via `poolOnlyHybrid.ts`. - **Docs / agents:** Updated invariant **L8**, ADR 0001 (merged with #189 `route/solve/best` text), integrator + limit-order docs; new [`skills/AGENTS_HYBRID_QUOTING.md`](skills/AGENTS_HYBRID_QUOTING.md). ### Verification checklist - [ ] LCD `hybrid_simulation` with `book_input: "0"` matches prior pool-only quotes on a funded pair - [ ] LCD `hybrid_reverse_simulation` with `pool_input: "1"`, `book_input: "0"` returns sensible `offer_amount` - [ ] Router `simulate_swap_operations` with `hybrid: null` hops matches direct pair hybrid pool-only quotes - [ ] Swap page / Trade panel quotes still load (`simulateSwap` → hybrid) - [ ] Indexer `GET route/solve?hybrid_optimize=true` still returns `estimated_amount_out` (no `simulation` LCD) - [ ] `cargo test -p cl8y-dex-tests limit_order_tests` green on your machine @brouie — please run the checklist on your environment and confirm before we close this issue.
PlasticDigits commented 2026-05-27 12:19:06 +00:00 (Migrated from gitlab.com)

mentioned in commit 9312fc01fa

mentioned in commit 9312fc01fa355d2e0ea6f70afa60c0d72057c215
PlasticDigits commented 2026-05-27 12:32:58 +00:00 (Migrated from gitlab.com)

mentioned in commit 6416ee50aa

mentioned in commit 6416ee50aa0067567eb7c52cf26edce42e4bd5a0
PlasticDigits commented 2026-05-27 12:33:49 +00:00 (Migrated from gitlab.com)

Verification complete (2026-05-27)

Ran the full checklist on LocalTerra + host Postgres + indexer :3001 + frontend :5173 + bot swarm (30/30).

Checklist

  • LCD hybrid_simulation with book_input: "0" — EMBER→CORAL 1M offer → return_amount 950297, book_return_amount 0
  • LCD hybrid_reverse_simulation with pool_input: "1", book_input: "0" — sensible offer_amount (1052 for ask 1000 CORAL)
  • Router simulate_swap_operations with hybrid: null — amount 950297 matches direct pair pool-only hybrid
  • Swap page quotes load — 1000 EMBER → 940.3 CORAL (hybrid simulateSwap), route spread check rendered
  • Indexer GET /api/v1/route/solve?hybrid_optimize=true — estimated_amount_out 950297, 1 hop
  • cargo test -p cl8y-dex-tests limit_order_tests — 34 passed
  • cargo test --test api_route_solve — 14 passed (after fix below)

Bug fixed

Indexer hybrid_route_opt degraded fallback still queried removed legacy simulation LCD → 502 on grid failure. Replaced with pool-only hybrid_simulation (book_input: 0). Merged to main as 6416ee5, pushed; indexer restarted locally.

Acceptance criteria

All production quoting paths use hybrid queries only; router/indexer/frontend verified on live stack.

## Verification complete (2026-05-27) Ran the full checklist on LocalTerra + host Postgres + indexer :3001 + frontend :5173 + bot swarm (30/30). ### Checklist - [x] LCD `hybrid_simulation` with `book_input: "0"` — EMBER→CORAL 1M offer → `return_amount` 950297, `book_return_amount` 0 - [x] LCD `hybrid_reverse_simulation` with `pool_input: "1"`, `book_input: "0"` — sensible `offer_amount` (1052 for ask 1000 CORAL) - [x] Router `simulate_swap_operations` with `hybrid: null` — amount 950297 matches direct pair pool-only hybrid - [x] Swap page quotes load — 1000 EMBER → 940.3 CORAL (hybrid `simulateSwap`), route spread check rendered - [x] Indexer `GET /api/v1/route/solve?hybrid_optimize=true` — `estimated_amount_out` 950297, 1 hop - [x] `cargo test -p cl8y-dex-tests limit_order_tests` — 34 passed - [x] `cargo test --test api_route_solve` — 14 passed (after fix below) ### Bug fixed Indexer `hybrid_route_opt` degraded fallback still queried removed legacy `simulation` LCD → 502 on grid failure. Replaced with pool-only `hybrid_simulation` (`book_input: 0`). Merged to `main` as `6416ee5`, pushed; indexer restarted locally. ### Acceptance criteria All production quoting paths use hybrid queries only; router/indexer/frontend verified on live stack.
PlasticDigits (Migrated from gitlab.com) closed this issue 2026-05-27 12:33:51 +00:00
PlasticDigits commented 2026-05-29 03:09:58 +00:00 (Migrated from gitlab.com)

mentioned in issue #209

mentioned in issue #209
ghost1 commented 2026-06-05 11:24:43 +00:00 (Migrated from gitlab.com)

mentioned in commit 616c44c6e9

mentioned in commit 616c44c6e92cf973d5c1993ce80cdf54b8e3a0de
PlasticDigits commented 2026-06-05 13:44:36 +00:00 (Migrated from gitlab.com)

mentioned in issue #332

mentioned in issue #332
PlasticDigits commented 2026-08-30 05:24:14 +00:00 (Migrated from gitlab.com)

mentioned in issue #707

mentioned in issue #707
PlasticDigits commented 2026-08-30 05:24:16 +00:00 (Migrated from gitlab.com)

mentioned in issue #708

mentioned in issue #708
PlasticDigits commented 2026-08-31 05:36:04 +00:00 (Migrated from gitlab.com)

mentioned in issue #713

mentioned in issue #713
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
code/cl8y-dex-terraclassic#190
No description provided.