fix(orderbook): reject and recover unfillable limit orders #1409

Merged
PlasticDigits merged 2 commits from fix/issue-1399-unfillable-orders into main 2026-10-06 02:11:18 +00:00
Owner

What

Reject economically unfillable orders on single/batch/ladder placement and repricing, then park legacy unfillable rows during bounded matching or permissionless cleaning even with zero dust thresholds. Makers retain owner-only escrow claims; zero-value claims omit CW20 transfers. Post-fill economic tails park without evicting healthy orders merely because a taker budget is small.

Align indexer book simulation with contract Decimal18 reciprocal rounding, the 500-step scan cap, and legacy expired/zero row scan positions. Add 21 regressions, numbered UF1399 invariants, integrator documentation, and an agent verifier with explicit unavailable-check skip policy.

Why

Tiny in-band orders previously remained linked indefinitely and consumed every bounded head scan, hiding useful liquidity. Placement size and price bounds alone did not prevent the clog. Escrow, FIFO, maker/scan/park caps, pause, blacklist, freeze, slippage and opt-in greedy behavior are preserved.

Fixes #1399; implements the remaining source remediation from closed #1225.

Testing

  • make verify-issue-1399: 8 PASS, 0 FAIL, 0 SKIP in source scope. Focused contract and indexer tests run twice.
  • Full contract workspace: 897 tests passed, including 550 integration tests and 97 pair tests.
  • Indexer book simulation: 27 tests passed twice; DB hybrid route integration: 9 tests passed, including an in-band invalid prefix longer than the scan cap.
  • Strict common/pair Clippy, all targets, -D warnings; changed Rust formatting and documentation crosslinks. Commit hooks also passed full contract lint and staged Gitleaks.
  • Swap and liquidity behavior covered by synthetic contract fixtures.
  • Wallet/device signing, optimized-wasm migration/gas and production rollout: not performed in this source implementation PR. No UI changes or screenshots are required.

Checklist

  • AC1: Placement, repricing and ladder paths reject unfillable rows across supported decimal combinations and checked overflow.
  • AC2: Legacy unexpired rows recover under zero thresholds; FIFO, escrow claims and double-refund protections remain intact.
  • AC3: More than 500 invalid heads make bounded cleanup progress without increasing scan/park/maker limits.
  • AC4: Execute, contract simulation and indexer agree; no-zero-payout and expired-prefix regressions pass.
  • No production credentials, keys or addresses added; fixtures use synthetic identities.
  • Invariants and third-party agent instructions documented and crosslinked.

Agents should read the verification checklist and receipt and UF1399 playbook, run make verify-issue-1399, and check only criteria supported by evidence. Unavailable checks may be SKIP with an observed reason and overall PASS WITH SKIPS when every executed check passes. Executed failures remain FAIL until corrected and retested; skipped rollout does not establish deployment.

After merge, deploy the updated indexer and migrate pair wasm, then verify clean/claim behavior and gas before live acceptance. Initial fixture/diagnostic failures were corrected and retested; none were hidden as skips.

## What Reject economically unfillable orders on single/batch/ladder placement and repricing, then park legacy unfillable rows during bounded matching or permissionless cleaning even with zero dust thresholds. Makers retain owner-only escrow claims; zero-value claims omit CW20 transfers. Post-fill economic tails park without evicting healthy orders merely because a taker budget is small. Align indexer book simulation with contract Decimal18 reciprocal rounding, the 500-step scan cap, and legacy expired/zero row scan positions. Add 21 regressions, numbered UF1399 invariants, integrator documentation, and an agent verifier with explicit unavailable-check skip policy. ## Why Tiny in-band orders previously remained linked indefinitely and consumed every bounded head scan, hiding useful liquidity. Placement size and price bounds alone did not prevent the clog. Escrow, FIFO, maker/scan/park caps, pause, blacklist, freeze, slippage and opt-in greedy behavior are preserved. Fixes #1399; implements the remaining source remediation from closed #1225. ## Testing - [x] `make verify-issue-1399`: 8 PASS, 0 FAIL, 0 SKIP in source scope. Focused contract and indexer tests run twice. - [x] Full contract workspace: 897 tests passed, including 550 integration tests and 97 pair tests. - [x] Indexer book simulation: 27 tests passed twice; DB hybrid route integration: 9 tests passed, including an in-band invalid prefix longer than the scan cap. - [x] Strict common/pair Clippy, all targets, `-D warnings`; changed Rust formatting and documentation crosslinks. Commit hooks also passed full contract lint and staged Gitleaks. - [x] Swap and liquidity behavior covered by synthetic contract fixtures. - [ ] Wallet/device signing, optimized-wasm migration/gas and production rollout: not performed in this source implementation PR. No UI changes or screenshots are required. ## Checklist - [x] AC1: Placement, repricing and ladder paths reject unfillable rows across supported decimal combinations and checked overflow. - [x] AC2: Legacy unexpired rows recover under zero thresholds; FIFO, escrow claims and double-refund protections remain intact. - [x] AC3: More than 500 invalid heads make bounded cleanup progress without increasing scan/park/maker limits. - [x] AC4: Execute, contract simulation and indexer agree; no-zero-payout and expired-prefix regressions pass. - [x] No production credentials, keys or addresses added; fixtures use synthetic identities. - [x] Invariants and third-party agent instructions documented and crosslinked. Agents should read [the verification checklist and receipt](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/branch/fix/issue-1399-unfillable-orders/docs/qa/issue-1399/README.md) and [UF1399 playbook](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/branch/fix/issue-1399-unfillable-orders/skills/AGENTS_UNFILLABLE_LIMIT_ORDERS.md), run `make verify-issue-1399`, and check only criteria supported by evidence. Unavailable checks may be SKIP with an observed reason and overall PASS WITH SKIPS when every executed check passes. Executed failures remain FAIL until corrected and retested; skipped rollout does not establish deployment. After merge, deploy the updated indexer and migrate pair wasm, then verify clean/claim behavior and gas before live acceptance. Initial fixture/diagnostic failures were corrected and retested; none were hidden as skips.
fix(orderbook): reject and park unfillable limit orders
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
f5ae76b12d
Validate post-fee maker fillability and preserve bounded escrow recovery for legacy rows. Align contract and indexer simulation arithmetic and document verification invariants.
Integrate unfillable order recovery and reverse-query tests [skip ci]
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline failed
ca03fed6f9
Sign in to join this conversation.
No reviewers
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!1409
No description provided.