Contract: emit swap_index on limit_order_fill wasm events (GitLab #316 follow-up) #331
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#331
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?
Parent
Follow-up to GitLab #316 (indexer-side
swap_indexlinkage — closed). Short-term parser walk-order attribution is merged; this issue tracks the long-term contract change for durable LCD replay.Current codebase
parse_limit_order_fillsinindexer/src/indexer/parser.rsassigns each fill a per-pairswap_indexby walking wasm events in tx order — fills emitted before their parentswapaction receive the upcoming ordinal (same counter asparse_swaps).process_limit_order_filllinks vialimit_order_fills::swap_id_for_tx_pair_index(tx_hash, pair_id, swap_index)(seeindexer/tests/limit_fill_swap_linkage.rs).limit_order_fill_eventinsmartcontracts/contracts/pair/src/orderbook.rsemitsaction=limit_order_fillwithorder_id,side,maker,price, token amounts, andcommission_amount— noswap_indexattribute.swap_indexis absent from wasm attrs, the indexer infers it from event ordering. This breaks if LCD merges/splits wasm events differently than the live chain, or on historical replay after parser logic changes.Why this is needed
Without an on-chain
swap_indexon eachlimit_order_fillevent:swap_eventsrow when a tx has multiple swaps on the same pair (router revisit, batch).docs/integrators-hybrid-volume.md) depend on correct fill→swap linkage for hybrid book attribution.Emitting
swap_indexon-chain makes attribution self-describing and matches the(tx_hash, pair_id, swap_index)unique key added in GitLab #287.Constraints / guardrails
swap_index(infer from walk order) for historical txs.swap_indexon a fill must match the per-pair swap ordinal the pair contract uses for that tx — same definition asswapevent ordering (0-based, incremented once per completed swap on the pair within the tx).limit_order_fillsdedup key(tx_hash, pair_id, order_id).docs/contracts-security-audit.mdevent catalog and integrator docs.Relevant files
smartcontracts/contracts/pair/src/orderbook.rs—limit_order_fill_event,fill_events.push(...)call sitessmartcontracts/contracts/pair/src/contract.rs,orderbook.rsmatch walksmartcontracts/tests/src/limit_order_tests.rs—hybrid_swap_emits_limit_order_fill_events, multi-fill casesindexer/src/indexer/parser.rs—parse_limit_order_fill_segment,parse_limit_order_fillsindexer/src/db/queries/limit_order_fills.rsindexer/tests/limit_fill_swap_linkage.rsdocs/integrators-hybrid-volume.md,docs/limit-orders.mdRecommended direction
swap_indexcounter through hybrid execute (increment after each swap wasm event is finalized). Pass the current ordinal intolimit_order_fill_event(..., swap_index)for each maker fill produced by that swap.swap_index(stringifiedu32) to thelimit_order_fillwasm event attributes.parse_limit_order_fill_segment, read optionalswap_indexattr; when present and valid, use it instead of walk-order inference. Keep inference as fallback.swap_indexattrs links correctly.Acceptance criteria
limit_order_fillwasm event emitted during hybrid execute includesswap_indexmatching the parent swap's per-pair ordinal.swap_indexwhen present; walk-order inference unchanged for legacy txs.limit_fill_swap_linkagetest extended with wasm fixture using explicit attrs.make test-contractsand indexer integration tests green.Test plan — all paths
swap_index=0on fill eventswap_index0 and 1 respectivelylimit_order_filleventspool_input=0) with fillsswap_indexpresentswap_indexTest plan — attack / abuse / hack vectors
swap_indexin LCD attrs (indexer ingest)swap_indexwith no matching swap rowswap_id_for_tx_pair_indexreturnsNone; fill stored without bogusswap_event_idswap_indexfill_existsdedup prevents double-insertVerification criteria
cargo test -p cl8y-dex-tests hybrid_swap_emits_limit_order_fillpasses withswap_indexattr assertions.cargo test --test limit_fill_swap_linkagepasses (extended).limit_order_fill_eventincludesswap_index.swap_indexon fill wasm attrs.marked as related to #316
mentioned in commit
b6c3cae169mentioned in merge request !817
Implementation in MR !817: https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/merge_requests/99
Contract stamps
swap_indexonlimit_order_fillevents; indexer prefers on-chain attr. Agent labels removed; issue stays open for merge + deploy verification.mentioned in commit
13be1a3398mentioned in commit
cd58a65edbmentioned in commit
767cdd7092mentioned in commit
21f6eb6ada