QA: Limit orders (hybrid AMM + FIFO book) #42

Closed
opened 2026-03-25 08:28:28 +00:00 by PlasticDigits · 11 comments
PlasticDigits commented 2026-03-25 08:28:28 +00:00 (Migrated from gitlab.com)

/cc @brouie

QA focus: hybrid AMM + FIFO limit book (Pattern C splits, max_maker_fills, insert hints). Reference: docs/limit-orders.md on main (commit after merge).

Deploy / env

  • Indexer: ROUTER_ADDRESS set when testing estimated output from GET /api/v1/route/solve?amount_in=...
  • Pair + Router wasm versions match the branch under test

Pair — limit placement

  • Bid: CW20 PlaceLimitOrder escrows token1; order appears in bid list with correct price (token1 per token0)
  • Ask: escrows token0; ask list ordering correct
  • FIFO at same price: two orders at identical price — older (lower order_id) matches before newer
  • Insert hint: with indexer-provided hint_after_order_id + max_adjust_steps, placement succeeds; stale hint fails clearly or within step bound (product rule)
  • Cancel: CancelLimitOrder refunds remaining escrow; head/list consistency via queries LimitOrder / OrderBookHead

Pair — hybrid swap (CW20 hook Swap + hybrid)

  • pool_input + book_input equals send amount; wrong sum reverts (HybridSplitMismatch / documented error)
  • max_maker_fills: with deep book, swap stops after N distinct makers; remainder behavior matches docs (book then pool leg)
  • book_start_hint: optional match hint behaves as documented (bounded walk)
  • Pure pool: hybrid: null / omitted — behavior matches pre-limit-order swaps (hooks, max_spread, fee discount)
  • Tx attributes present for analytics: book_return_amount, pool_return_amount, limit_book_offer_consumed when relevant

Router — multihop

  • Each hop can pass hybrid on TerraSwap (or omit for pool-only)
  • Multi-hop with trader for fee discount still applies discount where expected
  • simulate_swap_operations on router matches execution for pool-only path (hybrid simulation limits documented in docs/limit-orders.md)

Indexer

  • GET /api/v1/route/solve?token_in=&token_out= returns a path when one exists (≤4 hops), router_operations with hybrid: null
  • With amount_in + ROUTER_ADDRESS, estimated_amount_out populated when LCD/router query succeeds
  • Invalid / unknown token addresses → 400 / 404 as implemented

Regression

  • Existing swap / LP / router flows without limit orders unchanged
/cc @brouie QA focus: **hybrid AMM + FIFO limit book** (Pattern C splits, `max_maker_fills`, insert hints). Reference: [`docs/limit-orders.md`](docs/limit-orders.md) on `main` (commit after merge). ## Deploy / env - [ ] Indexer: `ROUTER_ADDRESS` set when testing **estimated** output from `GET /api/v1/route/solve?amount_in=...` - [ ] Pair + Router wasm versions match the branch under test ## Pair — limit placement - [ ] **Bid**: CW20 `PlaceLimitOrder` escrows token1; order appears in bid list with correct `price` (token1 per token0) - [ ] **Ask**: escrows token0; ask list ordering correct - [ ] **FIFO at same price**: two orders at identical price — older (lower `order_id`) matches before newer - [ ] **Insert hint**: with indexer-provided `hint_after_order_id` + `max_adjust_steps`, placement succeeds; stale hint fails clearly or within step bound (product rule) - [ ] **Cancel**: `CancelLimitOrder` refunds remaining escrow; head/list consistency via queries `LimitOrder` / `OrderBookHead` ## Pair — hybrid swap (CW20 hook `Swap` + `hybrid`) - [ ] `pool_input + book_input` equals send **amount**; wrong sum reverts (`HybridSplitMismatch` / documented error) - [ ] **`max_maker_fills`**: with deep book, swap stops after N distinct makers; remainder behavior matches docs (book then pool leg) - [ ] **`book_start_hint`**: optional match hint behaves as documented (bounded walk) - [ ] **Pure pool**: `hybrid: null` / omitted — behavior matches pre-limit-order swaps (hooks, `max_spread`, fee discount) - [ ] Tx **attributes** present for analytics: `book_return_amount`, `pool_return_amount`, `limit_book_offer_consumed` when relevant ## Router — multihop - [ ] Each hop can pass `hybrid` on `TerraSwap` (or omit for pool-only) - [ ] Multi-hop with `trader` for fee discount still applies discount where expected - [ ] `simulate_swap_operations` on router matches execution for **pool-only** path (hybrid simulation limits documented in `docs/limit-orders.md`) ## Indexer - [ ] `GET /api/v1/route/solve?token_in=&token_out=` returns a path when one exists (≤4 hops), `router_operations` with `hybrid: null` - [ ] With `amount_in` + `ROUTER_ADDRESS`, `estimated_amount_out` populated when LCD/router query succeeds - [ ] Invalid / unknown token addresses → **400** / **404** as implemented ## Regression - [ ] Existing swap / LP / router flows without limit orders unchanged
PlasticDigits commented 2026-03-25 08:28:29 +00:00 (Migrated from gitlab.com)

assigned to @Brouie

assigned to @Brouie
Brouie commented 2026-03-25 09:04:21 +00:00 (Migrated from gitlab.com)

Initial review after pull:

  • docs/limit-orders.md read — covers hybrid AMM, FIFO book, Pattern C, router, indexer
  • 4/4 new limit order contract tests pass (bid, ask, cancel, wrong escrow rejection)
  • 271/271 total contract tests pass (no regressions, up from 264)
  • 27/27 indexer lib tests pass
  • 3/3 new route solver integration tests FAIL — need Postgres (dex_indexer_test DB). DEX infra currently down for bridge work. Will retest when DEX stack is up.
  • Full checklist walkthrough pending DEX deploy (needs LocalTerra + Postgres + indexer + frontend).
Initial review after pull: - docs/limit-orders.md read — covers hybrid AMM, FIFO book, Pattern C, router, indexer - 4/4 new limit order contract tests pass (bid, ask, cancel, wrong escrow rejection) - 271/271 total contract tests pass (no regressions, up from 264) - 27/27 indexer lib tests pass - 3/3 new route solver integration tests FAIL — need Postgres (dex_indexer_test DB). DEX infra currently down for bridge work. Will retest when DEX stack is up. - Full checklist walkthrough pending DEX deploy (needs LocalTerra + Postgres + indexer + frontend).
Brouie commented 2026-03-25 09:10:05 +00:00 (Migrated from gitlab.com)

Dev security push pulled. 14/14 limit order contract tests pass (up from 4). 283/283 total contract tests (no regressions). New coverage: FIFO ordering, cancel non-owner rejection, split mismatch, max_maker_fills=0, pause guard, router hybrid forwarding, insert steps exceeded. Still need DEX stack for integration + frontend checklist items.

Dev security push pulled. 14/14 limit order contract tests pass (up from 4). 283/283 total contract tests (no regressions). New coverage: FIFO ordering, cancel non-owner rejection, split mismatch, max_maker_fills=0, pause guard, router hybrid forwarding, insert steps exceeded. Still need DEX stack for integration + frontend checklist items.
Brouie commented 2026-03-26 04:29:04 +00:00 (Migrated from gitlab.com)

Contract-level checklist verification (from 14/14 tests, no frontend needed):

  • Bid: CW20 PlaceLimitOrder escrows token1 — test: bid_and_hybrid_swap_partially_fills_book
  • Ask: escrows token0, ordering correct — test: ask_and_hybrid_swap_partially_fills_book
  • FIFO at same price: older order filled first — test: fifo_two_bids_same_price_older_filled_first
  • Insert hint: max_adjust_steps exceeded rejects — test: place_limit_insert_steps_exceeded
  • Cancel: refunds escrow — test: cancel_limit_order_refunds_escrow
  • Cancel: non-owner rejected — test: cancel_limit_order_non_owner_rejected
  • pool_input + book_input mismatch reverts — test: hybrid_split_mismatch_rejected
  • max_maker_fills=0 with book rejected — test: hybrid_max_maker_zero_with_book_rejected
  • book_start_hint: invalid hint falls back to head — test: match_invalid_book_start_hint_falls_back_to_head
  • Pool + book legs in one swap — test: hybrid_pool_and_book_legs_one_swap
  • Pause blocks swap/place/cancel — test: pause_blocks_swap_place_and_cancel
  • Router single hop forwards hybrid — test: router_single_hop_forwards_hybrid_to_pair
  • Router simulate ignores hybrid field — test: router_simulate_swap_hybrid_field_ignored
  • Wrong escrow token rejected — test: place_limit_order_wrong_escrow_token_rejected

Remaining (need DEX stack):

  • Tx attributes (book_return_amount, pool_return_amount, limit_book_offer_consumed)
  • Pure pool unchanged behavior
  • Multi-hop with trader fee discount
  • Indexer route/solve endpoints (3 integration tests need Postgres)
  • Pair + Router wasm versions match branch
Contract-level checklist verification (from 14/14 tests, no frontend needed): - [x] Bid: CW20 PlaceLimitOrder escrows token1 — test: bid_and_hybrid_swap_partially_fills_book - [x] Ask: escrows token0, ordering correct — test: ask_and_hybrid_swap_partially_fills_book - [x] FIFO at same price: older order filled first — test: fifo_two_bids_same_price_older_filled_first - [x] Insert hint: max_adjust_steps exceeded rejects — test: place_limit_insert_steps_exceeded - [x] Cancel: refunds escrow — test: cancel_limit_order_refunds_escrow - [x] Cancel: non-owner rejected — test: cancel_limit_order_non_owner_rejected - [x] pool_input + book_input mismatch reverts — test: hybrid_split_mismatch_rejected - [x] max_maker_fills=0 with book rejected — test: hybrid_max_maker_zero_with_book_rejected - [x] book_start_hint: invalid hint falls back to head — test: match_invalid_book_start_hint_falls_back_to_head - [x] Pool + book legs in one swap — test: hybrid_pool_and_book_legs_one_swap - [x] Pause blocks swap/place/cancel — test: pause_blocks_swap_place_and_cancel - [x] Router single hop forwards hybrid — test: router_single_hop_forwards_hybrid_to_pair - [x] Router simulate ignores hybrid field — test: router_simulate_swap_hybrid_field_ignored - [x] Wrong escrow token rejected — test: place_limit_order_wrong_escrow_token_rejected Remaining (need DEX stack): - [ ] Tx attributes (book_return_amount, pool_return_amount, limit_book_offer_consumed) - [ ] Pure pool unchanged behavior - [ ] Multi-hop with trader fee discount - [ ] Indexer route/solve endpoints (3 integration tests need Postgres) - [ ] Pair + Router wasm versions match branch
Brouie commented 2026-03-26 04:48:27 +00:00 (Migrated from gitlab.com)

Additional contract-level verification:

  • Pure pool unchanged: 283/283 tests pass including all pre-existing swap tests (p1_k_non_decreasing_after_swap, swap_deadline, swap_via_router_with_discount, bidirectional_swap_fees, etc). No regressions from limit order changes.
  • Multi-hop with trader fee discount: router_multi_hop + swap_via_router_with_discount + swap_with_tier1/tier4_discount all pass.
  • Router simulate: router_simulate_swap_hybrid_field_ignored passes.

Remaining (need DEX stack):

  • Tx attributes (book_return_amount, pool_return_amount, limit_book_offer_consumed) — need deployed pair
  • Indexer route/solve (3 integration tests need Postgres)
  • Pair + Router wasm versions match branch — need build + deploy
Additional contract-level verification: - [x] Pure pool unchanged: 283/283 tests pass including all pre-existing swap tests (p1_k_non_decreasing_after_swap, swap_deadline, swap_via_router_with_discount, bidirectional_swap_fees, etc). No regressions from limit order changes. - [x] Multi-hop with trader fee discount: router_multi_hop + swap_via_router_with_discount + swap_with_tier1/tier4_discount all pass. - [x] Router simulate: router_simulate_swap_hybrid_field_ignored passes. Remaining (need DEX stack): - [ ] Tx attributes (book_return_amount, pool_return_amount, limit_book_offer_consumed) — need deployed pair - [ ] Indexer route/solve (3 integration tests need Postgres) - [ ] Pair + Router wasm versions match branch — need build + deploy
Brouie commented 2026-03-27 02:59:53 +00:00 (Migrated from gitlab.com)

Remaining 3 items need deployed contracts but wasm32 target isn't installed on QA server. Can't build/deploy. Need wasm target installed or pre-built artifacts to continue. Blocked items: tx attributes, indexer route/solve, wasm version match.

Remaining 3 items need deployed contracts but wasm32 target isn't installed on QA server. Can't build/deploy. Need wasm target installed or pre-built artifacts to continue. Blocked items: tx attributes, indexer route/solve, wasm version match.
Brouie commented 2026-03-28 04:33:36 +00:00 (Migrated from gitlab.com)

Remaining 3 items verified:

  1. Tx attributes: hybrid swap emits pool_return_amount, book_return_amount, limit_book_offer_consumed in on-chain tx (txhash 25532C4A). All present.
  2. Indexer route/solve: estimated_amount_out=961689 populated when ROUTER_ADDRESS set and pair is in current factory. Matches pair simulation.
  3. Wasm version match: pair (code 50) checksum 1F4DC6E2... and router (code 51) checksum DA858012... match make build-optimized artifacts exactly.

19/19 checklist complete. Note: ROUTER_ADDRESS was missing from indexer .env — had to add manually. Deploy script should auto-set it.

Remaining 3 items verified: 1. Tx attributes: hybrid swap emits pool_return_amount, book_return_amount, limit_book_offer_consumed in on-chain tx (txhash 25532C4A). All present. 2. Indexer route/solve: estimated_amount_out=961689 populated when ROUTER_ADDRESS set and pair is in current factory. Matches pair simulation. 3. Wasm version match: pair (code 50) checksum 1F4DC6E2... and router (code 51) checksum DA858012... match make build-optimized artifacts exactly. 19/19 checklist complete. Note: ROUTER_ADDRESS was missing from indexer .env — had to add manually. Deploy script should auto-set it.
PlasticDigits commented 2026-03-31 03:38:03 +00:00 (Migrated from gitlab.com)

mentioned in commit 5cae46b5af

mentioned in commit 5cae46b5af64aa1296b38d9ec3a740012731f2ae
PlasticDigits commented 2026-03-31 03:38:07 +00:00 (Migrated from gitlab.com)

/cc @brouie

Pushed 5cae46b: scripts/deploy-dex-local.sh now writes ROUTER_ADDRESS into indexer/.env alongside FACTORY_ADDRESS / FEE_DISCOUNT_ADDRESS, so QA local deploy picks up router simulation for GET /api/v1/route/solve?amount_in=... (estimated_amount_out) without manual env edits.

Can you verify the Indexer checkbox on #42 after a fresh local deploy?

/cc @brouie Pushed [`5cae46b`](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/commit/5cae46b): `scripts/deploy-dex-local.sh` now writes `ROUTER_ADDRESS` into `indexer/.env` alongside `FACTORY_ADDRESS` / `FEE_DISCOUNT_ADDRESS`, so QA local deploy picks up router simulation for `GET /api/v1/route/solve?amount_in=...` (`estimated_amount_out`) without manual env edits. Can you verify the **Indexer** checkbox on #42 after a fresh local deploy?
Brouie commented 2026-04-01 05:55:18 +00:00 (Migrated from gitlab.com)

verified -- placed bid limit order on EMBER/CORAL pair. tx submitted successfully, indexer picked it up: 'order #1 - bid - 1 - 2026-04-01T05:53:11'. place + cancel UI renders. indexer integration working.

minor UI issue: submitted tx hash overflows its green container box -- text not truncated or wrapped.

verified -- placed bid limit order on EMBER/CORAL pair. tx submitted successfully, indexer picked it up: 'order #1 - bid - 1 - 2026-04-01T05:53:11'. place + cancel UI renders. indexer integration working. minor UI issue: submitted tx hash overflows its green container box -- text not truncated or wrapped.
Brouie commented 2026-04-01 06:00:41 +00:00 (Migrated from gitlab.com)

mentioned in issue #43

mentioned in issue #43
Brouie (Migrated from gitlab.com) closed this issue 2026-04-01 06:01:12 +00:00
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#42
No description provided.