Wire hint_after_order_id for single limit placement (frontend + batch wire + integrators) #261
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#261
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
Expose
hint_after_order_idon single-rung limit placement (retail batch hook) and wire the dApp deep book to compute and pass the predecessor order id. On-chain O(1) insert verification landed in #256;UpdateLimitOrderPriceand book Edit already pass hints inpair.ts. Single Place limit still omits the hint, and the batch wire schema has no per-rung hint field — so clients cannot benefit from deep-book topology on new orders.Current codebase
On-chain (post-#256)
find_insert_bid/find_insert_askhonorhint_afterwith verified O(1) fast path + bounded head-walk fallback (orderbook.rs).UpdateLimitOrderPriceacceptshint_after_order_id(pair.rsExecuteMsg).last_placed_hintfrom the prior successful rung id internally (limit_placement.rs) — helps monotonic multi-rung txs only.LimitOrderPlacementItemhas nohint_after_order_idfield (dex-common/limit_placement.rs) — external clients cannot pass a hint on a single batch rung.Frontend dApp
updateLimitOrderPrice(..., hintAfterOrderId?)encodeshint_after_order_id(pair.ts).placeLimitOrderWithAllowance/LimitOrderPlacementItemWireomit hint; retail path sends batch with one item, no predecessor (pair.ts).OrderBookPanelsetshintAfterOrderIdfrom the prior row index →LimitBookTicketDraft→useLimitOrderUpdatePriceMutation(OrderBookPanel.tsx,TradeOrderTicket.tsx).TradeOrderTicket,LimitOrdersPage.tsx) never passes a hint regardless of loaded deep-book pages (useLimitBookInfinite).Indexer / integrators
GET /api/v1/pairs/{addr}/limit-bookreturns paginated resting orders withorder_id,price,prev/nextfrom LCD (limit_book_lcd.rs) — sufficient to compute predecessor off-chain.Why this is needed
max_adjust_steps; head-only walks fail withLimitInsertStepsExceededeven when the UI/indexer already loaded the local book neighborhood.PlaceLimitOrderBatch(single item) need a stable wire field, not only internal batch chaining.Constraints and guardrails
max_adjust_steps.#[serde(default)]on new batch item field —null/omit preserves today’s behavior.nullhint (current behavior).Relevant files
smartcontracts/packages/dex-common/src/limit_placement.rssmartcontracts/contracts/pair/src/limit_placement.rssmartcontracts/contracts/pair/src/orderbook.rsfrontend-dapp/src/services/terraclassic/pair.tsfrontend-dapp/src/utils/limitBookInsertHint.tsfrontend-dapp/src/components/trade/TradeOrderTicket.tsxfrontend-dapp/src/pages/LimitOrdersPage.tsxfrontend-dapp/src/hooks/useLimitBookInfinite.ts,OrderBookPanel.tsxdocs/limit-orders.md,docs/frontend.md,docs/integrators.mddocs/contracts-security-audit.mdL14skills/AGENTS_FRONTEND_DEEP_ORDER_BOOK.md,skills/AGENTS_FRONTEND_LIMIT_ORDER_PLACEMENT_GAS.md,skills/AGENTS_LIMIT_ORDER_BATCH_LADDER.mdpair.test.ts,limit_order_tests.rs, new Vitest for hint resolverRecommended direction
#[serde(default)] hint_after_order_id: Option<u64>toLimitOrderPlacementItem. Inexecute_place_limit_orders_batch, passitem.hint_after_order_id.or(last_placed_hint)intoinsert_*_with_id(explicit client hint wins over internal chain).LimitOrderPlacementItemWire+placeLimitOrderWithAllowance(..., hintAfterOrderId?)to encode the field on the single-rung batch item.resolveLimitInsertHintAfter(side, price, loadedOrders[])using bid/ask sort rules — returnorder_idof the order immediately before the insert slot, ornullif head insert / insufficient loaded depth / ambiguous gap across pagination.useLimitBookInfinitepages cover the insert neighborhood for the ticket side+price, pass resolved hint; otherwisenull. Share resolver between/tradeand/limits.integrators.mdand cross-link L14; update agent skills. Indexer HTTP API unchanged unless follow-up adds optionalsuggested_hint_after(not required for this issue).pair.test.tsencode assertion.Acceptance criteria
LimitOrderPlacementItemaccepts optionalhint_after_order_id; single-rung batch txs can carry it on-chain.placeLimitOrderWithAllowanceaccepts and encodes optional hint.Test plan (functional paths)
order_id; placement succeeds with Low stepsnull; head insertlast_placed_hint/limitsstandalone page/tradeTest plan (attack / abuse / hack vectors)
Verification criteria
cargo test— batch item hint + existing #256 hint tests green.cd frontend-dapp && npm test— resolver unit tests +pair.test.tsencode hint.LimitInsertStepsExceededor skip (document observed gas delta)./tradedeep book loaded → place at mid-book price → confirm tx succeeds with Low/Medium preset.Related
mentioned in commit
6b22febcdbImplementation summary (merged to
main@6b22feb)Wired
hint_after_order_idfor single-rung limit placement end-to-end per issue scope.On-chain
#[serde(default)] hint_after_order_id: Option<u64>toLimitOrderPlacementItem(dex-common).item.hint_after_order_id.or(last_placed_hint)— explicit client hint wins over internal ladder chaining.limit_batch_item_explicit_hint_places_on_deep_book.Frontend
LimitOrderPlacementItemWire+placeLimitOrderWithAllowance(..., hintAfterOrderId?)encode the batch item field.resolveLimitInsertHintAfter/flattenLimitBookPagesinfrontend-dapp/src/utils/limitBookInsertHint.ts./trade(TradeOrderTicket) and/limits(LimitOrdersPage) resolve hint from mergeduseLimitBookInfinitepages at submit; omit when head insert or pagination gap.Docs / invariants
docs/contracts-security-audit.mdwith #261 cross-links.docs/limit-orders.md,docs/frontend.md,docs/integrators.md(new § Batch placement insert hints).AGENTS_FRONTEND_DEEP_ORDER_BOOK,AGENTS_FRONTEND_LIMIT_ORDER_PLACEMENT_GAS,AGENTS_LIMIT_ORDER_BATCH_LADDER.Tests run locally
cargo test limit_batch_item_explicit_hintnpx vitest --run limitBookInsertHint.test.ts pair.test.ts(hint encode + resolver cases)Verification checklist
cargo test limit_batch_item_explicit_hint_places_on_deep_bookpassescd frontend-dapp && npx vitest --run src/utils/__tests__/limitBookInsertHint.test.ts src/services/terraclassic/__tests__/pair.test.tspasseshint_after_order_idwhen book loaded/trade: deep book loaded → place at price between two visible rows → succeeds with Low (16) where head-only walk would fail/limitsstandalone page: same hint behavior as/tradehintAfterOrderId(#247 regression)Follow-ups (optional, not in scope)
suggested_hint_afteronlimit-bookrows — not required; clients can compute from paginated walk.Requesting verification from the QA agent team when convenient.
mentioned in issue #265
#261 verified — good to close. hint_after_order_id wired end to end for single-rung placement.
Checklist:
Live deep-book placement (/trade + /limits, place mid-book with Low/Medium steps where a head-only walk would hit LimitInsertStepsExceeded) is the browser layer. The logic is fully covered here: the contract test proves the deep-book hint insert, and the resolver+encode tests prove the UI resolves the predecessor from the loaded book pages and passes it on the wire.
Verified end to end. @PlasticDigits