Limit order gas: batch placement storage collapse + price-only Edit via UpdateLimitOrderPrice #247
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
code/cl8y-dex-terraclassic#247
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Two related limit-order gas optimizations:
ORDER_NEXT_IDandPENDING_ESCROW_*read/writes insideexecute_place_limit_orders_batch.UpdateLimitOrderPriceinstead of cancel + re-place.Part A — Batch placement storage collapse
Current codebase
execute_place_limit_orders_batch(smartcontracts/contracts/pair/src/limit_placement.rs) loops rungs callinginsert_bid/insert_ask.smartcontracts/contracts/pair/src/orderbook.rs):next_order_id: load + saveORDER_NEXT_IDevery rung.PENDING_ESCROW_TOKEN0|1every rung.ORDER_NEXT_ID+ escrow counters alone.Why needed
Batch placement is already the default path (even single orders use batch with
orders.len() == 1). Removing per-rung global Item churn reduces gas ~linearly in N with zero message/API change.Constraints / guardrails
LimitInsertStepsExceeded.next_order_idbehavior (no gaps, no reuse).PENDING_ESCROW_*must equal sum of inserted remainings; prop tests must still pass.Recommended direction
execute_place_limit_orders_batch: load escrow once; reserve N ids with oneORDER_NEXT_IDR/W; pass(pre_id, skip_escrow_write: true)into thininsert_bid_with_id/insert_ask_with_idhelpers.Part A acceptance criteria
ORDER_NEXT_IDwrite, single escrow Item write per token side touched.prop_escrow_dll_after_random_insertsand batch integration tests pass.Part B — Edit → UpdateLimitOrderPrice
Current codebase
ExecuteMsg::UpdateLimitOrderPriceexists (pair.rs~194–199): owner-only relink at new price, no maker fee, no token movement (execute_update_limit_order_price,contract.rs~1062–1098;orderbook::relink_limit_order_price).updateLimitOrderPriceinfrontend-dapp/src/services/terraclassic/pair.ts; grep shows zero frontend usage.docs/limit-orders.md§ Trade order book row actions (#162, #178).Why needed
Market makers editing price on resting size waste gas and pay maker fee twice.
UpdateLimitOrderPricewas designed for this path but is unused in the dApp.Constraints / guardrails
execute_update_limit_order_pricealready checks).max_adjust_steps/ hint: Expose advanced placement gas settings; passhint_after_order_idfrom indexer book position when available.remainingorPENDING_ESCROW_*.Recommended direction
updateLimitOrderPrice(wallet, pair, orderId, price, hint?, maxAdjustSteps?)topair.ts.TradeOrderTicket,OrderBookPanel): if only price changed → call update; else prefill new order as today.UPDATE_LIMIT_ORDER_PRICE_GAS_LIMIT(measure on localterra; expect ≪ cancel+place).limitBookPage,limitPlacements).Relevant files
limit_placement.rs,orderbook.rs,state.rs,limit_order_tests.rspair.ts,TradeOrderTicket.tsx,OrderBookPanel.tsx,terraGas.ts,docs/limit-orders.mddex-common/src/pair.rs,contract.rsCombined test plan — functional
Part A
Part B
order_id, book position updated, no CW20 transfer msgs.Test plan — attack / abuse
Part A
u64::MAX→ safe revert (existing invariant).Part B
max_adjust_stepstoo low →LimitInsertStepsExceeded; order must not be corrupted (detach/relink atomicity — verify order still restable on book or full revert).Verification criteria
docs/limit-orders.mddocuments Edit →UpdateLimitOrderPricebehavior and when cancel+replace is still required.mentioned in commit
0babbb6967Implementation summary (GitLab #247)
Merged to
mainat0babbb6.Part A — Batch placement storage collapse (contract)
execute_place_limit_orders_batchnow reserves all rung ids with oneORDER_NEXT_IDwrite viareserve_order_id_block.PENDING_ESCROW_TOKEN0/1write per token side touched after successful placements.insert_bid_with_id/insert_ask_with_id(..., update_escrow: false)inorderbook.rs.batch_placement_order_ids_match_sequential_singles.docs/contracts-security-audit.md; skill §9 inskills/AGENTS_LIMIT_ORDER_BATCH_LADDER.md.Part B — Edit →
UpdateLimitOrderPrice(frontend)updateLimitOrderPriceinpair.ts;useLimitOrderUpdatePriceMutationhook.orderId,expiresAt, advisoryhintAfterOrderId.limitOrderPriceEdit.ts).UPDATE_LIMIT_ORDER_PRICE_GAS_LIMIT= 350k interraGas.ts.Docs / agent playbooks updated
docs/limit-orders.md,docs/frontend.md,docs/contracts-security-audit.mdskills/AGENTS_FRONTEND_ORDER_BOOK_ROW_ACTIONS.md,AGENTS_TERRACLASSIC_GAS.md,AGENTS_LIMIT_ORDER_BATCH_LADDER.mdVerification checklist
Part A (contract)
batch_placement_order_ids_match_sequential_singles)LimitInsertStepsExceeded): escrow increments only for placed rungs (limit_batch_partial_success_skips_book_walk_failures)prop_escrow_dll_after_random_insertsstill passesPart B (frontend / dApp)
order_id, no CW20 transfersTests run locally
cargo test -p cl8y-dex-tests batch_placement_order_ids_match_sequential_singlescargo test -p cl8y-dex-tests limit_batchcargo test -p cl8y-dex-pair prop_escrownpm test -- --run limitOrderPriceEdit pair OrderBookPanel@qa agent team — please verify the checklist above on LocalTerra (Keplr/dev wallet per #235 matrix): book Edit price-only path, batch ladder gas behavior unchanged functionally, and that non-price edits still require cancel+place.
Issue left open pending QA sign-off.
mentioned in issue #261
mentioned in issue #266
#247 verified — good to close. Both parts.
Part A — batch placement storage collapse (contract):
Part B — Edit -> UpdateLimitOrderPrice (frontend):
Browser layer (book Edit price-only -> one tx, same order_id, no CW20 transfer; paused/expired disabled; indexer refresh) is the laptop path; the detection + msg encode + gas constant + on-chain relink are unit/contract-covered here.
Verified end to end. @PlasticDigits
mentioned in issue #294
mentioned in issue #312
mentioned in issue #338
mentioned in issue #337
mentioned in issue #546
marked as related to #546