Raise limit book walk caps: 1k scan steps, 100 maker fills #262

Closed
opened 2026-06-01 02:30:48 +00:00 by PlasticDigits · 16 comments
PlasticDigits commented 2026-06-01 02:30:48 +00:00 (Migrated from gitlab.com)

Summary

Raise on-chain book-walk ceilings so taker hybrid swaps can traverse deeper books and fill more distinct makers per tx, while keeping simulation parity, gas estimates, and the ~30M block gas cap as hard guardrails.

Related (closed): #248 (CW20 transfer aggregation — lowers per-fill message cost, making higher fill counts more practical).

Current codebase

  • Constants (smartcontracts/packages/dex-common/src/pair.rs):
    • MAX_MAKER_FILLS_HARD_CAP = 256 — clamps HybridSwapParams.max_maker_fills in match_bids / match_asks / simulate_match_* (makers_used cap).
    • MAX_SCAN_STEPS_EXTRA = 32; MAX_SCAN_STEPS = 288 (MAX_MAKER_FILLS_HARD_CAP + EXTRA) — every DLL iteration (fills, expired parks, expired skips, zero-remaining continues) counts one step; walk stops when budget exhausted (#254).
    • MAX_EXPIRED_PARKS_PER_SWAP = 15 — write-heavy parks per walk (#250).
  • Match loops (smartcontracts/contracts/pair/src/orderbook.rs): book_walk_step + makers_used < cap where cap = max_maker_fills.min(MAX_MAKER_FILLS_HARD_CAP).
  • Swap integration (smartcontracts/contracts/pair/src/contract.rs): partial book consumption spills to pool; attrs scan_steps_capped, expired_parks_*.
  • Frontend / localnet gas (must stay aligned after constant change):
    • frontend-dapp/src/services/terraclassic/hybridBookWalkLimits.ts
    • frontend-dapp/src/services/terraclassic/hybridSwapGas.ts (#249, #260)
    • packages/localnet-trading-swarm/src/gas.ts
  • Indexer / route solver: passes max_maker_fills on hybrid routes; book sim mirrors execute caps.
  • Invariant L5 (docs/contracts-security-audit.md): documents current 256 / 288 / 15 caps.

Why this is needed

  • Post-#248 aggregation, incremental cost per additional maker fill is dominated by storage + events, not extra CW20 submessages — deeper ladders are cheaper per fill than before.
  • Taker depth: A scan budget of ~1k steps lets hybrid swaps walk through longer expired prefixes and deep FIFO queues without leaving stale head orders indefinitely (today 288 steps can truncate walks on busy books — scan_steps_capped=true).
  • Maker fills: A hard cap of 100 distinct makers per swap is a practical upper bound for liquidity consumption while bounding worst-case transfer count (≤ 102 CW20 msgs: 100 makers + taker + treasury per L10).
  • Product: Integrators and the dApp can request higher max_maker_fills (up to 100) and rely on a 1k scan budget for taker-side book walks without unbounded gas (prior #254 motivation).

Constraints and guardrails

  • Decouple scan budget from maker cap: MAX_SCAN_STEPS should reach 1000 without implying MAX_MAKER_FILLS_HARD_CAP = 1000. Recommended: MAX_MAKER_FILLS_HARD_CAP = 100, MAX_SCAN_STEPS = 1000 (revisit MAX_SCAN_STEPS_EXTRA or define scan cap independently — document formula in dex-common and docs/limit-orders.md).
  • Block gas: Benchmark worst-case hybrid swap (100 makers + max scan + max parks) on LocalTerra; must stay well under ~30M gas per tx; reduce MAX_EXPIRED_PARKS_PER_SWAP or parks-per-sweep if needed.
  • Simulation parity: simulate_match_* and HybridSimulation must use the same caps as execute (#254).
  • Do not weaken L1 escrow accounting, L10 aggregation conservation, or L7 commission totals.
  • Paused pairs: unchanged.
  • Migration: constant-only preferred; if governance-tunable caps are added, follow existing UpdateLimitOrderConfig / factory patterns.
  • Note for implementers: Today MAX_MAKER_FILLS_HARD_CAP is 256; target 100 is a lower hard ceiling on fills but a higher scan budget — confirm product intent in review (may be intentional trade-off: fewer fills, deeper walks).

Relevant files

Area Path
Constants smartcontracts/packages/dex-common/src/pair.rs
Match / sim smartcontracts/contracts/pair/src/orderbook.rs
Swap smartcontracts/contracts/pair/src/contract.rs
Docs docs/limit-orders.md, docs/contracts-security-audit.md (L5)
Tests smartcontracts/tests/src/limit_order_tests.rs, orderbook::proptest_limits, orderbook::expired_park_cap_tests
Frontend gas frontend-dapp/src/services/terraclassic/hybridBookWalkLimits.ts, hybridSwapGas.ts
Swarm gas packages/localnet-trading-swarm/src/gas.ts
Skills skills/AGENTS_TERRACLASSIC_GAS.md
  1. Set MAX_MAKER_FILLS_HARD_CAP = 100 and MAX_SCAN_STEPS = 1000 (adjust MAX_SCAN_STEPS_EXTRA or remove coupling — document rationale).
  2. Re-evaluate MAX_EXPIRED_PARKS_PER_SWAP vs new scan budget (parks are write-heavy; may stay 15–32 or scale modestly with benchmarks).
  3. Update proptest / cap tests that assume 256 / 288.
  4. Sync frontend + swarm gas formulas; open or close follow-up #260 as appropriate.
  5. Record LocalTerra gas_used for M=1, 10, 50, 100 makers and scan-capped expired-prefix scenarios (#252 style).

Acceptance criteria

  • max_maker_fills > 100 is clamped to 100 on execute and sim.
  • Book walks stop at 1000 scan steps; scan_steps_capped attr when binding.
  • HybridSimulation matches execute when either cap binds.
  • All existing make test-contracts limit-order tests updated/green.
  • hybridBookWalkLimits.ts / hybridSwapGas.ts / localnet-trading-swarm gas constants match dex-common.
  • docs/limit-orders.md and invariant L5 updated with new numbers.

Test plan — functional paths

  • Hybrid swap with max_maker_fills=100 fills 100 distinct makers (bid + ask sides).
  • Request max_maker_fills=200 → clamped to 100; economics correct.
  • Expired prefix longer than scan budget: walk stops at 1000 steps, pool spillover, attrs set.
  • simulate_match_* and HybridSimulation parity when scan cap binds (not only maker cap).
  • Book-only / pool-only / split hybrid regressions unchanged when caps not hit.
  • Property tests: prop_match_* maker cap; scan step never exceeds 1000.

Test plan — attack / abuse vectors

  • Gas griefing: Adversary cannot force >1000 ORDERS reads per swap via params (hard cap).
  • Maker cap griefing: max_maker_fills=100 still bounds distinct fills; no extra CW20 transfers beyond L10.
  • Overflow: Aggregated payouts / commissions with 100 fills use checked_add.
  • Partial walk + slippage: Truncated book walk cannot bypass assert_max_spread / pool spill rules.
  • Indexer: scan_steps_capped / fill events still consistent for analytics.

Verification criteria

  • make test-contracts green.
  • LocalTerra benchmark table in issue comment or docs/limit-orders.md (100-maker hybrid, scan-capped walk).
  • Manual hybrid swap on localterra with deep book; balances match spreadsheet.
  • No regression to #248 aggregation tests (orderbook::aggregation_tests).
## Summary Raise on-chain book-walk ceilings so taker hybrid swaps can traverse deeper books and fill more distinct makers per tx, while keeping simulation parity, gas estimates, and the ~30M block gas cap as hard guardrails. **Related (closed):** [#248](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/issues/248) (CW20 transfer aggregation — lowers per-fill message cost, making higher fill counts more practical). ## Current codebase - **Constants** (`smartcontracts/packages/dex-common/src/pair.rs`): - `MAX_MAKER_FILLS_HARD_CAP` = **256** — clamps `HybridSwapParams.max_maker_fills` in `match_bids` / `match_asks` / `simulate_match_*` (`makers_used` cap). - `MAX_SCAN_STEPS_EXTRA` = **32**; `MAX_SCAN_STEPS` = **288** (`MAX_MAKER_FILLS_HARD_CAP + EXTRA`) — every DLL iteration (fills, expired parks, expired skips, zero-remaining continues) counts one step; walk stops when budget exhausted ([#254](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/issues/254)). - `MAX_EXPIRED_PARKS_PER_SWAP` = **15** — write-heavy parks per walk ([#250](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/issues/250)). - **Match loops** (`smartcontracts/contracts/pair/src/orderbook.rs`): `book_walk_step` + `makers_used < cap` where `cap = max_maker_fills.min(MAX_MAKER_FILLS_HARD_CAP)`. - **Swap integration** (`smartcontracts/contracts/pair/src/contract.rs`): partial book consumption spills to pool; attrs `scan_steps_capped`, `expired_parks_*`. - **Frontend / localnet gas** (must stay aligned after constant change): - `frontend-dapp/src/services/terraclassic/hybridBookWalkLimits.ts` - `frontend-dapp/src/services/terraclassic/hybridSwapGas.ts` ([#249](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/issues/249), [#260](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/issues/260)) - `packages/localnet-trading-swarm/src/gas.ts` - **Indexer / route solver:** passes `max_maker_fills` on hybrid routes; book sim mirrors execute caps. - **Invariant L5** ([`docs/contracts-security-audit.md`](./docs/contracts-security-audit.md)): documents current 256 / 288 / 15 caps. ## Why this is needed - Post-**#248** aggregation, incremental cost per additional maker fill is dominated by storage + events, not extra CW20 submessages — deeper ladders are cheaper per fill than before. - **Taker depth:** A scan budget of **~1k** steps lets hybrid swaps walk through longer expired prefixes and deep FIFO queues without leaving stale head orders indefinitely (today **288** steps can truncate walks on busy books — `scan_steps_capped=true`). - **Maker fills:** A hard cap of **100** distinct makers per swap is a practical upper bound for liquidity consumption while bounding worst-case transfer count (**≤ 102** CW20 msgs: 100 makers + taker + treasury per **L10**). - **Product:** Integrators and the dApp can request higher `max_maker_fills` (up to 100) and rely on a 1k scan budget for taker-side book walks without unbounded gas (prior #254 motivation). ## Constraints and guardrails - **Decouple scan budget from maker cap:** `MAX_SCAN_STEPS` should reach **1000** without implying `MAX_MAKER_FILLS_HARD_CAP` = 1000. Recommended: `MAX_MAKER_FILLS_HARD_CAP = 100`, `MAX_SCAN_STEPS = 1000` (revisit `MAX_SCAN_STEPS_EXTRA` or define scan cap independently — document formula in `dex-common` and `docs/limit-orders.md`). - **Block gas:** Benchmark worst-case hybrid swap (100 makers + max scan + max parks) on LocalTerra; must stay **well under ~30M** gas per tx; reduce `MAX_EXPIRED_PARKS_PER_SWAP` or parks-per-sweep if needed. - **Simulation parity:** `simulate_match_*` and `HybridSimulation` must use the **same** caps as execute ([#254](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/issues/254)). - **Do not** weaken **L1** escrow accounting, **L10** aggregation conservation, or **L7** commission totals. - **Paused pairs:** unchanged. - **Migration:** constant-only preferred; if governance-tunable caps are added, follow existing `UpdateLimitOrderConfig` / factory patterns. - **Note for implementers:** Today `MAX_MAKER_FILLS_HARD_CAP` is **256**; target **100** is a **lower** hard ceiling on fills but a **higher** scan budget — confirm product intent in review (may be intentional trade-off: fewer fills, deeper walks). ## Relevant files | Area | Path | |------|------| | Constants | `smartcontracts/packages/dex-common/src/pair.rs` | | Match / sim | `smartcontracts/contracts/pair/src/orderbook.rs` | | Swap | `smartcontracts/contracts/pair/src/contract.rs` | | Docs | `docs/limit-orders.md`, `docs/contracts-security-audit.md` (L5) | | Tests | `smartcontracts/tests/src/limit_order_tests.rs`, `orderbook::proptest_limits`, `orderbook::expired_park_cap_tests` | | Frontend gas | `frontend-dapp/src/services/terraclassic/hybridBookWalkLimits.ts`, `hybridSwapGas.ts` | | Swarm gas | `packages/localnet-trading-swarm/src/gas.ts` | | Skills | `skills/AGENTS_TERRACLASSIC_GAS.md` | ## Recommended solution direction 1. Set `MAX_MAKER_FILLS_HARD_CAP = 100` and `MAX_SCAN_STEPS = 1000` (adjust `MAX_SCAN_STEPS_EXTRA` or remove coupling — document rationale). 2. Re-evaluate `MAX_EXPIRED_PARKS_PER_SWAP` vs new scan budget (parks are write-heavy; may stay 15–32 or scale modestly with benchmarks). 3. Update proptest / cap tests that assume 256 / 288. 4. Sync frontend + swarm gas formulas; open or close follow-up **#260** as appropriate. 5. Record LocalTerra `gas_used` for M=1, 10, 50, 100 makers and scan-capped expired-prefix scenarios ([#252](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/issues/252) style). ## Acceptance criteria - [ ] `max_maker_fills` > 100 is clamped to **100** on execute and sim. - [ ] Book walks stop at **1000** scan steps; `scan_steps_capped` attr when binding. - [ ] `HybridSimulation` matches execute when either cap binds. - [ ] All existing `make test-contracts` limit-order tests updated/green. - [ ] `hybridBookWalkLimits.ts` / `hybridSwapGas.ts` / `localnet-trading-swarm` gas constants match `dex-common`. - [ ] `docs/limit-orders.md` and invariant **L5** updated with new numbers. ## Test plan — functional paths - [ ] Hybrid swap with `max_maker_fills=100` fills 100 distinct makers (bid + ask sides). - [ ] Request `max_maker_fills=200` → clamped to 100; economics correct. - [ ] Expired prefix longer than scan budget: walk stops at 1000 steps, pool spillover, attrs set. - [ ] `simulate_match_*` and `HybridSimulation` parity when scan cap binds (not only maker cap). - [ ] Book-only / pool-only / split hybrid regressions unchanged when caps not hit. - [ ] Property tests: `prop_match_*` maker cap; scan step never exceeds 1000. ## Test plan — attack / abuse vectors - [ ] **Gas griefing:** Adversary cannot force >1000 `ORDERS` reads per swap via params (hard cap). - [ ] **Maker cap griefing:** `max_maker_fills=100` still bounds distinct fills; no extra CW20 transfers beyond **L10**. - [ ] **Overflow:** Aggregated payouts / commissions with 100 fills use `checked_add`. - [ ] **Partial walk + slippage:** Truncated book walk cannot bypass `assert_max_spread` / pool spill rules. - [ ] **Indexer:** `scan_steps_capped` / fill events still consistent for analytics. ## Verification criteria - [ ] `make test-contracts` green. - [ ] LocalTerra benchmark table in issue comment or `docs/limit-orders.md` (100-maker hybrid, scan-capped walk). - [ ] Manual hybrid swap on localterra with deep book; balances match spreadsheet. - [ ] No regression to **#248** aggregation tests (`orderbook::aggregation_tests`).
PlasticDigits commented 2026-06-01 02:30:49 +00:00 (Migrated from gitlab.com)

marked as related to #248

marked as related to #248
PlasticDigits commented 2026-06-01 02:30:50 +00:00 (Migrated from gitlab.com)

marked as related to #254

marked as related to #254
PlasticDigits commented 2026-06-01 02:56:31 +00:00 (Migrated from gitlab.com)

mentioned in commit eed8d177de

mentioned in commit eed8d177de198b0ab8493f962999694442834abc
PlasticDigits commented 2026-06-01 02:56:41 +00:00 (Migrated from gitlab.com)

Implementation summary (merged to main — eed8d17)

Raised on-chain hybrid book-walk ceilings per #262 and kept execute/sim/dApp/swarm in lockstep.

On-chain (dex-common::pair)

  • MAX_MAKER_FILLS_HARD_CAP: 256 → 100 (clamps caller max_maker_fills on execute + simulate_match_*)
  • MAX_SCAN_STEPS: 288 → 1000, decoupled from the maker cap (removed MAX_MAKER_FILLS_HARD_CAP + MAX_SCAN_STEPS_EXTRA coupling)
  • MAX_EXPIRED_PARKS_PER_SWAP: unchanged at 15

Match loops in orderbook.rs already use max_maker_fills.min(MAX_MAKER_FILLS_HARD_CAP) and book_walk_step against MAX_SCAN_STEPS — no logic changes required beyond constants.

Frontend / swarm gas

  • Mirrored caps in hybridBookWalkLimits.ts and localnet-trading-swarm/src/gas.ts
  • Offline worst-case scan envelope (1000 steps + 15 parks) now hits the existing HYBRID_SWAP_GAS_LIMIT (1.2M) ceiling for any book_input > 0 tx; unit tests updated accordingly

Docs / agent playbooks

  • Invariant L5 in docs/contracts-security-audit.md
  • docs/limit-orders.md (scan budget, gas formula, scan_steps_capped attr table)
  • docs/frontend.md, skills/AGENTS_TERRACLASSIC_GAS.md, skills/AGENTS_FRONTEND_LIMIT_PARKED_EXPIRED.md, gaps/GAP_1780200149.md

Tests run (green)

  • make test-contracts (336 integration + 27 pair unit tests, incl. scan-step cap + sim parity + proptest maker caps)
  • frontend-dapp — hybridSwapGas.test.ts, transactions.test.ts
  • localnet-trading-swarm — gas.test.ts

Verification checklist

  • make test-contracts green on your machine
  • Hybrid swap with max_maker_fills=100 fills up to 100 distinct makers (bid + ask)
  • Request max_maker_fills=200 → clamped to 100 on-chain; economics unchanged
  • Expired prefix longer than scan budget → walk stops at 1000 steps, scan_steps_capped=true, pool spillover
  • HybridSimulation matches execute when scan cap binds (not only maker cap)
  • Book-only / pool-only / split hybrid regressions when caps not hit
  • dApp hybrid swap gas estimate = 1.2M for any book leg with offline worst-case scan (expected after cap raise)
  • LocalTerra benchmark: 100-maker hybrid + scan-capped walk stays well under ~30M block gas (#252 style table)
  • No regression to #248 aggregation tests (orderbook::aggregation_tests)

Follow-ups

  • LocalTerra gas_used table for M=1/10/50/100 makers and scan-capped expired-prefix scenarios is still outstanding (#252); constants are raised but on-chain gas benchmarks should be recorded before mainnet deploy.
  • Consider whether HYBRID_SWAP_GAS_LIMIT (1.2M) should be raised separately if LocalTerra shows 100-maker + deep-scan txs need more headroom — current dApp envelope saturates at 1.2M for all book legs under offline worst case.
  • #260 can be closed as superseded by this cap alignment, or left open if further gas tuning is planned post-benchmark.

Please verify the checklist above on LocalTerra when convenient. QA agent team — this is ready for independent verification; issue left open until sign-off.

## Implementation summary (merged to `main` — `eed8d17`) Raised on-chain hybrid book-walk ceilings per #262 and kept execute/sim/dApp/swarm in lockstep. ### On-chain (`dex-common::pair`) - **`MAX_MAKER_FILLS_HARD_CAP`**: 256 → **100** (clamps caller `max_maker_fills` on execute + `simulate_match_*`) - **`MAX_SCAN_STEPS`**: 288 → **1000**, **decoupled** from the maker cap (removed `MAX_MAKER_FILLS_HARD_CAP + MAX_SCAN_STEPS_EXTRA` coupling) - **`MAX_EXPIRED_PARKS_PER_SWAP`**: unchanged at **15** Match loops in `orderbook.rs` already use `max_maker_fills.min(MAX_MAKER_FILLS_HARD_CAP)` and `book_walk_step` against `MAX_SCAN_STEPS` — no logic changes required beyond constants. ### Frontend / swarm gas - Mirrored caps in `hybridBookWalkLimits.ts` and `localnet-trading-swarm/src/gas.ts` - Offline worst-case scan envelope (1000 steps + 15 parks) now hits the existing **`HYBRID_SWAP_GAS_LIMIT` (1.2M)** ceiling for any `book_input > 0` tx; unit tests updated accordingly ### Docs / agent playbooks - Invariant **L5** in `docs/contracts-security-audit.md` - `docs/limit-orders.md` (scan budget, gas formula, `scan_steps_capped` attr table) - `docs/frontend.md`, `skills/AGENTS_TERRACLASSIC_GAS.md`, `skills/AGENTS_FRONTEND_LIMIT_PARKED_EXPIRED.md`, `gaps/GAP_1780200149.md` ### Tests run (green) - `make test-contracts` (336 integration + 27 pair unit tests, incl. scan-step cap + sim parity + proptest maker caps) - `frontend-dapp` — `hybridSwapGas.test.ts`, `transactions.test.ts` - `localnet-trading-swarm` — `gas.test.ts` --- ## Verification checklist - [ ] `make test-contracts` green on your machine - [ ] Hybrid swap with `max_maker_fills=100` fills up to 100 distinct makers (bid + ask) - [ ] Request `max_maker_fills=200` → clamped to 100 on-chain; economics unchanged - [ ] Expired prefix longer than scan budget → walk stops at 1000 steps, `scan_steps_capped=true`, pool spillover - [ ] `HybridSimulation` matches execute when scan cap binds (not only maker cap) - [ ] Book-only / pool-only / split hybrid regressions when caps not hit - [ ] dApp hybrid swap gas estimate = **1.2M** for any book leg with offline worst-case scan (expected after cap raise) - [ ] LocalTerra benchmark: 100-maker hybrid + scan-capped walk stays well under ~30M block gas ([#252](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/issues/252) style table) - [ ] No regression to #248 aggregation tests (`orderbook::aggregation_tests`) --- ## Follow-ups - **LocalTerra `gas_used` table** for M=1/10/50/100 makers and scan-capped expired-prefix scenarios is still outstanding ([#252](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/issues/252)); constants are raised but on-chain gas benchmarks should be recorded before mainnet deploy. - Consider whether **`HYBRID_SWAP_GAS_LIMIT` (1.2M)** should be raised separately if LocalTerra shows 100-maker + deep-scan txs need more headroom — current dApp envelope saturates at 1.2M for all book legs under offline worst case. - **#260** can be closed as superseded by this cap alignment, or left open if further gas tuning is planned post-benchmark. --- Please verify the checklist above on LocalTerra when convenient. QA agent team — this is ready for independent verification; issue left open until sign-off.
PlasticDigits commented 2026-06-01 02:59:32 +00:00 (Migrated from gitlab.com)

Gas math correction (#262 follow-up)

The prior #262 implementation set MAX_SCAN_STEPS = 1000 while keeping the dApp HYBRID_SWAP_GAS_LIMIT = 1.2M. That pairing was inconsistent with measured book-walk cost:

Budget ÷ ~19k gas/order-step ≈ orders walkable
30M block gas cap 30_000_000 / 19_000 ~1,578 (~1.5k)
15M dApp gas ceiling (proposed) 15_000_000 / 19_000 ~789

1000 scan steps implies we expect the chain to honor walks near the block ceiling while the wallet only budgets 1.2M — users would pay for a tx that cannot complete, or hit out of gas after signing too low a limit.

Corrected targets:

  1. MAX_SCAN_STEPS = 500 — conservative headroom under the 15M / ~19k ≈ 789 order budget (scan steps include parks/skips, not only fills).
  2. HYBRID_SWAP_GAS_LIMIT = 15_000_000 — raise the offline hybrid envelope so quote-driven Fee.gas can cover deep book walks without saturating at 1.2M while staying well under the 30M block cap.

On-chain MAX_MAKER_FILLS_HARD_CAP = 100 unchanged. Implementing in a follow-up commit to main/master.

## Gas math correction (#262 follow-up) The prior #262 implementation set **`MAX_SCAN_STEPS = 1000`** while keeping the dApp **`HYBRID_SWAP_GAS_LIMIT = 1.2M`**. That pairing was inconsistent with measured book-walk cost: | Budget | ÷ ~19k gas/order-step | ≈ orders walkable | |--------|----------------------|-------------------| | **30M** block gas cap | 30_000_000 / 19_000 | **~1,578** (~1.5k) | | **15M** dApp gas ceiling (proposed) | 15_000_000 / 19_000 | **~789** | **1000 scan steps** implies we expect the chain to honor walks near the **block** ceiling while the wallet only budgets **1.2M** — users would pay for a tx that cannot complete, or hit `out of gas` after signing too low a limit. **Corrected targets:** 1. **`MAX_SCAN_STEPS = 500`** — conservative headroom under the **15M / ~19k ≈ 789** order budget (scan steps include parks/skips, not only fills). 2. **`HYBRID_SWAP_GAS_LIMIT = 15_000_000`** — raise the offline hybrid envelope so quote-driven `Fee.gas` can cover deep book walks without saturating at 1.2M while staying well under the **30M** block cap. On-chain **`MAX_MAKER_FILLS_HARD_CAP = 100`** unchanged. Implementing in a follow-up commit to `main`/`master`.
PlasticDigits commented 2026-06-01 03:01:53 +00:00 (Migrated from gitlab.com)

mentioned in commit 2d07b8deab

mentioned in commit 2d07b8deab7c287590d512a76ea6c3233091e3fb
PlasticDigits commented 2026-06-01 03:01:53 +00:00 (Migrated from gitlab.com)

mentioned in commit 389a55bc5b

mentioned in commit 389a55bc5bb5dbbd99324fc43fdf953f5288055b
Brouie commented 2026-06-01 14:12:48 +00:00 (Migrated from gitlab.com)

mentioned in merge request !733

mentioned in merge request !733
Brouie commented 2026-06-01 15:33:57 +00:00 (Migrated from gitlab.com)

Verified #262 on d6701c4 (with the #264 proptest fix above applied — needed it for a green run).

Caps land as the corrected spec (MAX_MAKER_FILLS_HARD_CAP=100, MAX_SCAN_STEPS=500 not 1000,
HYBRID_SWAP_GAS_LIMIT=15M), aligned across dex-common, hybridBookWalkLimits.ts, hybridSwapGas.ts,
swarm gas.ts, docs/limit-orders.md and L5.

  • make test-contracts: 402 passed / 0 failed.
  • Clamp: .min(MAX_MAKER_FILLS_HARD_CAP) in all 4 match/sim fns; hybrid_swap_accepts_max_maker_fills_at_hard_cap.
  • Scan cap 500 + scan_steps_capped: match_bids_scan_steps_cap_bounds_expired_prefix_walk; live #254 scancap bench bounded/no-OOG.
  • Sim parity when scan binds: simulate_match_bids_scan_steps_cap_matches_execute.
  • No #248 regression: orderbook::aggregation_tests green.

Live 100-maker worst case on LocalTerra (fresh genesis, 99 distinct makers, single pair):

  • gas_used = 11,623,305 (gas_wanted 15.1M) — well under the ~30M block cap, under the 15M dApp envelope.
  • 99 limit_order_fill events; 101 CW20 payout transfers (99 makers + taker + treasury = the L10 ≤102 bound).
  • Partial book consumption spilled remainder to pool (book_return 97.2M + pool_return 21.4M), code=0.

Feeds the #252 gas table. Good to close from my side once the #264 proptest fix is merged.
@PlasticDigits

Verified #262 on d6701c4 (with the #264 proptest fix above applied — needed it for a green run). Caps land as the corrected spec (MAX_MAKER_FILLS_HARD_CAP=100, MAX_SCAN_STEPS=500 not 1000, HYBRID_SWAP_GAS_LIMIT=15M), aligned across dex-common, hybridBookWalkLimits.ts, hybridSwapGas.ts, swarm gas.ts, docs/limit-orders.md and L5. - make test-contracts: 402 passed / 0 failed. - Clamp: .min(MAX_MAKER_FILLS_HARD_CAP) in all 4 match/sim fns; hybrid_swap_accepts_max_maker_fills_at_hard_cap. - Scan cap 500 + scan_steps_capped: match_bids_scan_steps_cap_bounds_expired_prefix_walk; live #254 scancap bench bounded/no-OOG. - Sim parity when scan binds: simulate_match_bids_scan_steps_cap_matches_execute. - No #248 regression: orderbook::aggregation_tests green. Live 100-maker worst case on LocalTerra (fresh genesis, 99 distinct makers, single pair): - gas_used = 11,623,305 (gas_wanted 15.1M) — well under the ~30M block cap, under the 15M dApp envelope. - 99 limit_order_fill events; 101 CW20 payout transfers (99 makers + taker + treasury = the L10 ≤102 bound). - Partial book consumption spilled remainder to pool (book_return 97.2M + pool_return 21.4M), code=0. Feeds the #252 gas table. Good to close from my side once the #264 proptest fix is merged. @PlasticDigits
Brouie commented 2026-06-01 16:16:50 +00:00 (Migrated from gitlab.com)

mentioned in issue #269

mentioned in issue #269
Brouie commented 2026-06-01 16:29:50 +00:00 (Migrated from gitlab.com)

mentioned in issue #263

mentioned in issue #263
PlasticDigits (Migrated from gitlab.com) closed this issue 2026-06-02 06:52:47 +00:00
Brouie commented 2026-06-02 16:47:32 +00:00 (Migrated from gitlab.com)

mentioned in issue #260

mentioned in issue #260
Brouie commented 2026-06-02 17:03:23 +00:00 (Migrated from gitlab.com)

mentioned in issue #249

mentioned in issue #249
Brouie commented 2026-06-02 18:03:59 +00:00 (Migrated from gitlab.com)

mentioned in issue #252

mentioned in issue #252
Brouie commented 2026-06-05 02:19:54 +00:00 (Migrated from gitlab.com)

mentioned in issue #289

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

mentioned in issue #708

mentioned in issue #708
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#262
No description provided.